Part Number Hot Search : 
CD961B 0603GM 0603GM 330M35 MAX17 5R250 Q800314 11160
Product Description
Full Text Search
 

To Download BS66F360 Datasheet File

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


  Datasheet File OCR Text:
  enhanced touch a/d flash mcu with led driver bs66f340/bs66f350 BS66F360/bs66f370 revision: v1.40 date: de ? e ?? e ? 1 ?? ? 01 ? de ? e ?? e ? 1 ?? ? 01 ?
rev. 1.40 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 3 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver table of contents eates cpu featu ? es .............................................................................................................................. 7 pe ? iphe ? al featu ? es ...................................................................................................................... 7 gene?al des??iption ............................................................................................. 8 sele?tion ta?le ..................................................................................................... 9 blo?k diag?a? ...................................................................................................... 9 pin assign?ent ........... ....................................................................................... 10 pin des??iptions ................................................................................................ 1? a?solute maxi?u? ratings .............................................................................. 30 d.c. cha?a?te?isti?s ........................................................................................... 30 a.c. cha?a?te?isti?s ........................................................................................... 3? a/d conve?te? cha?a?te?isti?s ........... ............................................................... 33 te?pe?atu?e senso? ele?t?i?al cha?a?te?isti?s .............................................. 33 lvd/lvr ele?t?i?al cha?a?te?isti?s .................................................................. 34 tou?h key ele?t?i?al cha?a?te?isti?s ........... .................................................... 3? powe?-on reset cha?a?te?isti?s ........... ............................................................ 37 syste? a??hite?tu?e .......................................................................................... 38 clo ? king and pipelining .............................................................................................................. 38 p ? og ? a ? counte ? ........................................................................................................................ 39 sta ? k .......................................................................................................................................... 40 a ? ith ? eti ? and logi ? unit C alu ................................................................................................ 40 flash p?og?a? me?o?y ..................................................................................... 41 st ? u ? tu ? e ..................................................................................................................................... 41 spe ? ial ve ? to ? s .......................................................................................................................... 41 look-up ta ? le ............. ................................................................................................................ 4 ? ta ? le p ? og ? a ? exa ? ple ............................................................................................................. 4 ? in ci ?? uit p ? og ? a ?? ing C icp .................................................................................................... 43 on-chip de ? ug suppo ? t C ocds .............................................................................................. 44 in appli ? ation p ? og ? a ?? ing C iap ............................................................................................. 4 ? data me?o?y ...................................................................................................... ?? st ? u ? tu ? e ..................................................................................................................................... ?? data me ? o ? y add ? essing ........................................................................................................... ?? gene ? al pu ? pose data me ? o ? y ................................................................................................. ?? spe ? ial pu ? pose data me ? o ? y .................................................................................................. ?? spe?ial fun?tion registe? des??iption ............................................................ ?1 indi ? e ? t add ? essing registe ? s C iar0 ? iar1 ? iar ? .................................................................... ? 1 me ? o ? y pointe ? s C mp0 ? mp1h/mp1l ? mp ? h/mp ? l ................................................................ ? 1
rev. 1.40 ? de?e??e? 1?? ?01? rev. 1.40 3 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver p ? og ? a ? me ? o ? y bank pointe ? C pbp ............. .......................................................................... ? 3 a ?? u ? ulato ? C acc .................................................................................................................... ? 3 p ? og ? a ? counte ? low registe ? C pcl ....................................................................................... ? 3 look-up ta ? le registe ? s C tblp ? tbhp ? tblh .......................................................................... ? 4 status registe ? C status ......................................................................................................... ? 4 eeprom data memory ........... ........................................................................... 66 eeprom data me ? o ? y st ? u ? tu ? e ............................................................................................. ?? eeprom registe ? s ............ ....................................................................................................... ?? reading data f ? o ? the eeprom .............................................................................................. ? 7 w ? iting data to the eeprom ..................................................................................................... ? 8 w ? ite p ? ote ? tion .......................................................................................................................... ? 8 eeprom inte ?? upt ............. ........................................................................................................ ? 8 p ? og ? a ?? ing conside ? ations ............. ........................................................................................ ? 8 oscillators .......... ................................................................................................ 70 os ? illato ? ove ? view ............. ....................................................................................................... 70 system clock confgurations ..................................................................................................... 70 exte ? nal c ? ystal/ce ? a ? i ? os ? illato ? C hxt ................................................................................ 71 inte ? nal high speed rc os ? illato ? C hirc ................................................................................ 7 ? exte ? nal 3 ? .7 ? 8 khz c ? ystal os ? illato ? C lxt ............. ............................................................... 7 ? inte ? nal 3 ? khz os ? illato ? C lirc ................................................................................................ 73 operating modes and system clocks ............................................................. 74 syste ? clo ? ks ........................................................................................................................... 74 syste ? ope ? ation modes ........................................................................................................... 7 ? cont ? ol registe ? s ....................................................................................................................... 77 ope ? ating mode swit ? hing ......................................................................................................... 80 stand ? y cu ?? ent conside ? ations ................................................................................................ 84 wake-up ..................................................................................................................................... 84 watchdog timer ........... ...................................................................................... 85 wat ? hdog ti ? e ? clo ? k sou ?? e ................................................................................................... 8 ? wat ? hdog ti ? e ? cont ? ol registe ? ............. ................................................................................. 8 ? wat ? hdog ti ? e ? ope ? ation ........................................................................................................ 8 ? reset and initialisation ...................................................................................... 87 reset fun ? tions ............. ............................................................................................................ 87 reset initial conditions .............................................................................................................. 90 input/output ports ............................................................................................. 97 pull-high resisto ? s ................................................................................................................... 100 po ? t a wake-up ............. ........................................................................................................... 100 i/o po ? t cont ? ol registe ? s ........................................................................................................ 100 i/o po ? t sou ?? e cu ?? ent cont ? ol ............................................................................................... 100 pin-sha ? ed fun ? tions ............. .................................................................................................. 10 ? i/o pin st ? u ? tu ? es ..................................................................................................................... 111 p ? og ? a ?? ing conside ? ations ............. ...................................................................................... 11 ?
rev. 1.40 4 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver timer modules C tm .......... .............................................................................. 113 int ? odu ? tion .............................................................................................................................. 113 tm ope ? ation ............. .............................................................................................................. 113 tm clo ? k sou ?? e ............. ......................................................................................................... 113 tm inte ?? upts ............................................................................................................................ 114 tm exte ? nal pins ...................................................................................................................... 114 tm input/output pin sele ? tion ................................................................................................. 11 ? p ? og ? a ?? ing conside ? ations ............. ...................................................................................... 11 ? compact type tm C ctm ................................................................................ 117 co ? pa ? t tm ope ? ation ............................................................................................................ 117 co ? pa ? t type tm registe ? des ?? iption ................................................................................... 118 co ? pa ? t type tm ope ? ation modes ....................................................................................... 1 ?? standard type tm C stm .......... ...................................................................... 128 standa ? d tm ope ? ation ............. ............................................................................................... 1 ? 8 standa ? d type tm registe ? des ?? iption .................................................................................. 1 ? 9 standa ? d type tm ope ? ation modes ....................................................................................... 133 periodic type tm C ptm .................................................................................. 143 pe ? iodi ? tm ope ? ation ............. ................................................................................................ 143 pe ? iodi ? type tm registe ? des ?? iption .................................................................................... 144 pe ? iodi ? type tm ope ? ation modes ......................................................................................... 148 analog to digital converter .......... .................................................................. 157 a/d conve ? te ? ove ? view .......................................................................................................... 1 ? 7 registe ? s des ?? iptions ............................................................................................................. 1 ? 8 a/d conve ? te ? ope ? ation .......................................................................................................... 1 ? 3 a/d conve ? te ? refe ? en ? e voltage ............................................................................................ 1 ? 4 a/d conve ? te ? input pins ......................................................................................................... 1 ? 4 conve ? sion rate and ti ? ing diag ? a ? ..................................................................................... 1 ? 4 su ?? a ? y of a/d conve ? sion steps ............. ............................................................................. 1 ?? p ? og ? a ?? ing conside ? ations ............. ...................................................................................... 1 ?? a/d conve ? te ? t ? ansfe ? fun ? tion ............................................................................................. 1 ?? a/d p ? og ? a ?? ing exa ? ples .................................................................................................... 1 ? 7 serial interface module C sim ......................................................................... 169 spi inte ? fa ? e ............................................................................................................................ 1 ? 9 i ? c inte ? fa ? e ............ ................................................................................................................. 17 ? uart interface ................................................................................................. 184 uart exte ? nal pin ................................................................................................................... 18 ? uart data t ? ansfe ? s ? he ? e ................................................................................................... 18 ? uart status and cont ? ol registe ? s ......................................................................................... 18 ? baud rate gene ? ato ? ............................................................................................................... 191 uart setup and cont ? ol .......................................................................................................... 19 ? uart t ? ans ? itte ? ..................................................................................................................... 193 uart re ? eive ? ............. ........................................................................................................... 194 managing re ? eive ? e ?? o ? s ....................................................................................................... 19 ?
rev. 1.40 4 de?e??e? 1?? ?01? rev. 1.40 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver uart inte ?? upt st ? u ? tu ? e .......................................................................................................... 197 uart powe ? down and wake-up ............................................................................................ 198 touch key function ........................................................................................ 199 tou ? h key st ? u ? tu ? e ................................................................................................................. 199 touch key register defnition .................................................................................................. ? 00 tou ? h key ope ? ation ................................................................................................................ ? 0 ? tou ? h key inte ?? upt .................................................................................................................. ? 1 ? p ? og ? s ?? ing conside ? ations ................................................................................................... ? 1 ? low voltage detector C lvd .......... ................................................................. 213 lvd registe ? ............. ............................................................................................................... ? 13 lvd ope ? ation .......................................................................................................................... ? 14 interrupts .......................................................................................................... 215 inte ?? upt registe ? s .................................................................................................................... ? 1 ? inte ?? upt ope ? ation ................................................................................................................... ?? 0 exte ? nal inte ?? upt ............. ......................................................................................................... ?? 1 tou ? h key inte ?? upt .................................................................................................................. ??? uart t ? ansfe ? inte ?? upt ........................................................................................................... ??? a/d conve ? te ? inte ?? upt ............................................................................................................ ??? multi-fun ? tion inte ?? upt ............................................................................................................. ??? ti ? e base inte ?? upt .................................................................................................................. ?? 3 se ? ial inte ? fa ? e module inte ?? upt .............................................................................................. ?? 4 lvd inte ?? upt ............................................................................................................................ ??? eeprom inte ?? upt ............. ...................................................................................................... ??? tm inte ?? upt ............. ................................................................................................................. ??? p ? og ? a ?? ing conside ? ations ............. ...................................................................................... ??? application circuits ........... .............................................................................. 227 instruction set .................................................................................................. 228 int ? odu ? tion .............................................................................................................................. ?? 8 inst ? u ? tion ti ? ing ..................................................................................................................... ?? 8 moving and t ? ansfe ?? ing data .................................................................................................. ?? 8 a ? ith ? eti ? ope ? ations ............................................................................................................... ?? 8 logi ? al and rotate ope ? ation .................................................................................................. ?? 9 b ? an ? hes and cont ? ol t ? ansfe ? ................................................................................................ ?? 9 bit ope ? ations .......................................................................................................................... ?? 9 ta ? le read ope ? ations ............................................................................................................ ?? 9 othe ? ope ? ations ............. ......................................................................................................... ?? 9 instruction set summary .......... ...................................................................... 230 ta ? le conventions .................................................................................................................... ? 30 extended inst ? u ? tion set ............. ............................................................................................. ? 3 ? instruction defnition ....................................................................................... 234 extended instruction defnition ................................................................................................ ? 43
rev. 1.40 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 7 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver package information ....................................................................................... 250 ? 8-pin sop (300 ? il) outline di ? ensions ................................................................................ ?? 1 ? 8-pin ssop (1 ? 0 ? il) outline di ? ensions .............................................................................. ??? 44-pin lqfp (10 ?? 10 ?? ) (fp ? .0 ?? ) outline di ? ensions ................................................ ?? 3 48-pin lqfp (7 ?? 7 ?? ) outline di ? ensions ....................................................................... ?? 4 ? 4-pin lqfp (7 ?? 7 ?? ) outline di ? ensions ....................................................................... ???
rev. 1.40 ? de?e??e? 1?? ?01? rev. 1.40 7 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver features cpu features ? operating voltage ? f sys = 8mhz : 2.2v~5.5v ? f sys =12mhz : 2.7v~5.5v ? f sys =16mhz : 3.3v~5.5v ? up to 0.25s instruction cycle with 16mhz system clock at v dd =5v ? power down and wake-up functions to reduce power consumption ? oscillator type ? external high speed crystal C hxt ? internal high speed rc C hirc ? external 32.768khz crystal C lxt ? internal 32khz rc C lirc ? fully integrated internal 8/12/16mhz oscillator requires no external components ? multi-mode operation: normal, slow, idle and sleep ? all instructions executed in one to three instruction cycles ? table read instructions ? 115 powerful instructions ? up to 16-level subroutine nesting ? bit manipulation instruction peripheral features ? program memory: up to 32k16 ? data memory: up to 15368 ? true eeprom memory: 1288 ? fully integrated touch key functions C require no external components ? watchdog t imer function ? up to 60 bidirectional i/o lines ? two external interrupt lines shared with i/o pins ? multiple t imer modules for time measure, input capture, compare match output, pwm output function or single pulse output function ? serial interfaces module C sim for spi or i 2 c ? fully-duplex universal asynchronous receiver and t ransmitter interface C uart ? programming i/o source current ? dual t ime-base functions for generation of fxed time interrupt signals ? 8-channel 12-bit resolution a/d converter ? temperature sensor ? in application programming function C iap ? low voltage reset function ? low voltage detect function
rev. 1.40 8 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 9 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? flash program memory can be re-programmed up to 100,000 times ? flash program memory data retention > 10 years ? true eeprom data memory can be re-programmed up to 1,000,000 times ? true eeprom data memory data retention > 10 years ? wide range of available package types general description the series of devices are flash memory a/d type 8-bit high performance risc architecture microcontroller with fully integrated touch key functions. w ith all touch key functions provided internally and with the convenience of flash memory multi-programm ing features, each device has all the features to of fer designers a reliable and easy means of implementing t ouch keyes within their products applications. the t ouch ke y func tions a re ful ly i ntegrated c ompletely e liminating t he ne ed for e xternal components. in addition to the fash program memory , other memory includes an area of ram data memory as well as an area of true eeprom memory for storage of non-volatile data such as serial numbers, calibration data, etc. analog features include a multi-channel 12-bit a/d converter with temperature sensor . protective features such as an internal w atchdog t imer and low v oltage reset functions coupled with excellent noise immunity and esd protection ensure that reliable operation is maintained in hostile electrical environments. these devices also include fully integrated low and high speed oscillators which are fexibly used for different applications. the ability to operate and s witch dynamically betw een a range of operating modes using dif ferent clock sources gives users the ability to optimise microcontroller operation and minimise power consumption. easy communication with the outside world is provided using the internal uar t, i 2 c and spi inte rfaces, while the inclusion of fexible i/o programming features, timer modules and many other features further enhance device functionality and fexibility. the touch key devices will fnd excellent use in a huge range of modern t ouch key product applications such as instrumentation, household appliances, electronically controlled tools to name but a few.
rev. 1.40 8 de?e??e? 1?? ?01? rev. 1.40 9 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver selection table most features are common to all devices. the main features distinguishing them are memory capacity, i/ o c ount, t ouch modul e a nd ke y m umber, st ack c apacity a nd pa ckage t ypes. t he following table summarises the main features of each device. part no. program memory data memory data eeprom i/o a/d temp. sensor time base bs ?? f340 4k1 ? ? 1 ? 8 1 ? 88 ?? 1 ? - ? it8 ? bs ?? f3 ? 0 8k1 ? 7 ? 88 1 ? 88 40 1 ? - ? it8 ? bs ?? f3 ? 0 1 ? k1 ? 10 ? 48 1 ? 88 4 ? 1 ? - ? it8 ? bs ?? f370 3 ? k1 ? 1 ? 3 ? 8 1 ? 88 ? 0 1 ? - ? it8 ? part no. timer module touch module touch key sim uart stacks package bs ?? f340 10- ? it ctm ? 10- ? it ptm1 1 ? - ? it stm1 3 1 ? 8 ? 8ssop bs ?? f3 ? 0 10- ? it ctm ? 10- ? it ptm1 1 ? - ? it stm1 ? ? 0 8 44/48lqfp bs ?? f3 ? 0 10- ? it ctm ? 10- ? it ptm1 1 ? - ? it stm1 7 ? 8 1 ? ? 8sop 44/48lqfp bs ?? f370 10- ? it ctm ? 10- ? it ptm1 1 ? - ? it stm1 9 3 ? 1 ? 44/48/ ? 4lqfp note: as devices exist in more than one package format, the table reflects the situation for the package with the most pins. block diagram 8-?it risc mcu co?e i/o ti?e? modules flash p?og?a? me?o?y eeprom data me?o?y flash/eeprom p?og?a??ing ci??uit?y ti?e base sim (spi/i ? c) low voltage reset wat?hdog ti?e? low voltage dete?t inte??upt cont?olle? reset ci??uit exte?nal hxt os?illato? 1?-?it a/d conve?te? ram data me?o?y iap uart inte?nal hirc/lirc os?illato?s te?pe?atu?e senso? tou?h key modules exte?nal lxt os?illato?
rev. 1.40 10 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 11 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pin assignment 28 27 26 25 24 23 22 21 20 19 18 17 16 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 pe4/osc1 pe5/ctp1b/osc2 pb7/int1/key4/an7 pb6/ptck/key3/an6 pb5/stck/key2/an5 pb4/ptpi/ptpb/key1/an4 pa4/sdo/xt2 vss vdd pb0/sdi/sda/vref/an0 pb1/sck/scl/an1 pb2/ptpi/tx/ptp/an2 pa3/scs/xt1 pb3/rx/an3 pc0/key5 pc1/key6 pc3/key8 pc2/key7 pe0/key9 pa7/ctp1 pe3/stpi/stpb/key12 pe2/stpi/stp/key11 pa0/sdo/icpda/ocdsda pa1/ctp0 pa5/ctp0b pa6/ctck0/int0 pe1/key10 pa2/ctck1/scs/icpck/ocdsck bs66f340/bs66v340 28 ssop-a 28 27 26 25 24 23 22 21 20 19 18 17 16 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 BS66F360/bs66v360 28 sop-a pa6/ctck0/int0 pa7 pe3/stp0b/stp0i_1/key24 pe2/stp0/stp0i_0/key23 pd5/key18 pd6/key19 pd7/key20 pb4/ptp0b/ptp0i_1/an4/key1 pb5/stck0/an5/key2 pb6/ptck0/an6/key3 pa2/scsb/ocdsck pa0/sdo/ocdsda pa4/sdo/xt2 pa3/scsb/xt1 vss vdd pe5/ctck1/osc2 pe4/osc1 pa1/ctp0 pa5/ctp0b pb3/rx/an3 pb2/ptp0/ptp0i_0/tx/an2 pb0/vref/sdi/sda/resb/an0 pb1/sck/scl/an1 pd3/key16 pd2/key15 pd1/key14 pd4/key17
rev. 1.40 10 de?e??e? 1?? ?01? rev. 1.40 11 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs 66f 350/ bs 66v 350 44 lqfp -a 1 ? 3 4 ? ? 7 8 9 10 11 1? 13 14 1? 1? 17 18 19 ?0 ?1 ?? ?3 ?4 ?? ?? ?7 ?8 ?9 30 31 3? 33 343?3?37383940414?4344 pe?/ctck1/osc? pe4/osc1 pe7/ ctp 1b pe?/ ctp 1 pa1/ ctp 0 pa?/ ctp 0b pa?/ ctck 0/ int 0 pa7 pd3/key1? pd?/key1? pd1/key14 pa0/sdo/icpda/ocdsda vss pa4/sdo/xt? pa3/scs/xt1 vdd pb3/ rx /an3 pb0/sdi/sda/vref/an0 pb1/sck/scl/an1 pb?/ptpi/tx/ptp/an? pb7/ int 1/key4/an7 pb?/ ptck /key3/an? pb?/ stck /key?/an? pb4/ptpi/ptpb/key1/an4 pd?/key18 pd4/key17 pd?/key19 pe1 pe3/stpi/stpb pe?/stpi/stp pa?/scs/icpck/ocdsck nc nc nc nc nc pe0 pd7/key?0 pc7/key 1? pc?/key 11 pc?/key 10 pc4/key9 pc3/key8 pc?/key7 bs 66f 350/ bs 66v 350 48 lqfp -a 1 ? 3 4 ? ? 7 8 9 10 11 1? 13 14 1? 1? 17 18 19 ?0 ?1 ?? ?3 ?4 ?? ?? ?7 ?8 ?9 30 31 3? 33 34 3? 3? 4? 4?4748 37383940414?4344 pe?/ctck1/osc? pe4/osc1 pe7/ ctp 1b pe?/ ctp 1 pa1/ ctp 0 pa?/ ctp 0b pa?/ ctck 0/ int 0 pa7 pd3/key1? pd?/key1? pd1/key14 pd0/key13 pa0/sdo/icpda/ocdsda vss pa4/sdo/xt? pa3/scs/xt1 vdd pb3/rx/an3 pb0/sdi/sda/vref/an0 pb1/sck/scl/an1 pb?/ptpi/tx/ptp/an? pb7/ int 1/key4/an7 pb?/ ptck /key3/an? pb?/ stck /key?/an? pb4/ptpi/ptpb/key1/an4 pd?/key18 pd4/key17 pd?/key19 pe1 pe3/stpi/stpb pe?/stpi/stp pe0 pa?/scs/icpck/ocdsck nc nc nc nc nc nc pd7/key?0 pc3/key8 pc?/key7 pc1/key? pc0/key? pc?/key 10 pc4/key9 pc?/key 11 pc7/key 1?
rev. 1.40 1 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 13 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs 66f 360/ bs 66v 360 48 lqfp -a 1 ? 3 4 ? ? 7 8 9 10 11 1? 13 14 1? 1? 17 18 19 ?0 ?1 ?? ?3 ?4 ?? ?? ?7 ?8 ?9 30 31 3? 33 34 3? 3? 4? 4?4748 37383940414?4344 pe?/ctck1/osc? pe4/osc1 pe7/ ctp 1b/key ?? pe?/ ctp 1/key ?? pa1/ ctp 0 pa?/ ctp 0b pa?/ ctck 0/ int 0 pa7 pd3/key1? pd?/key1? pd1/key14 pd0/key13 pa0/sdo/icpda/ocdsda vss pa4/sdo/xt? pa3/scs/xt1 vdd pb3/rx/an3 pb0/sdi/sda/vref/an0 pb1/sck/scl/an1 pb?/ptpi/tx/ptp/an? pb7/ int 1/key4/an7 pb?/ ptck /key3/an? pb?/ stck /key?/an? pb4/ptpi/ptpb/key1/an4 pd?/key18 pd4/key17 pd?/key19 pe1/key?? pe3/stpi/stpb/key?4 pe?/stpi/stp/key?3 pe0/key?1 pa?/scs/icpck/ocdsck pf? pf4 pf3 pf? pf1/key ?8 pf0/key ?7 pd7/key?0 pc3/key8 pc?/key7 pc1/key? pc0/key? pc?/key 10 pc4/key9 pc?/key 11 pc7/key 1? bs 66f 360/ bs 66v 360 44 lqfp -a 1 ? 3 4 ? ? 7 8 9 10 11 1? 13 14 1? 1? 17 18 19 ?0 ?1 ?? ?3 ?4 ?? ?? ?7 ?8 ?9 30 31 3? 33 343?3?37383940414?4344 pe?/ctck1/osc? pe4/osc1 pe7/ ctp 1b/key ?? pe?/ ctp 1/key ?? pa1/ ctp 0 pa?/ ctp 0b pa?/ ctck 0/ int 0 pa7 pd3/key1? pd?/key1? pd1/key14 pa0/sdo/icpda/ocdsda vss pa4/sdo/xt? pa3/scs/xt1 vdd pb3/ rx /an3 pb0/sdi/sda/vref/an0 pb1/sck/scl/an1 pb?/ptpi/tx/ptp/an? pb7/ int 1/key4/an7 pb?/ ptck /key3/an? pb?/ stck /key?/an? pb4/ptpi/ptpb/key1/an4 pd?/key18 pd4/key17 pd?/key19 pe1 pe3/stpi/stpb/key?4 pe?/stpi/stp/key?3 pa?/scs/icpck/ocdsck pf? pf3 pf? pf1/key ?8 pf0/key ?7 pe0 pd7/key?0 pc7/key 1? pc?/key 11 pc?/key 10 pc4/key9 pc3/key8 pc?/key7
rev. 1.40 1? de?e??e? 1?? ?01? rev. 1.40 13 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f370/bs66v370 44 lqfp-a 1 ? 3 4 ? ? 7 8 9 10 11 1? 13 14 1? 1? 17 18 19 ?0 ?1 ?? ?3 ?4 ?? ?? ?7 ?8 ?9 30 31 3? 33 343? 3? 37 38 39 40 414? 4344 pe?/ctck1/osc? pe4/osc1 pe7/ctp1b/key?? pe?/ctp1/key?? pa1/ctp0 pa?/ctp0b pa?/ctck0/int0 pa7 pd3/key1? pd?/key1? pd1/key14 vss pa4/sdo/xt? pa3/scs/xt1 vdd pb3/rx/an3 pb0/vref/sdi/sda/an0 pb1/sck/scl/an1 pb?/ptp/ptpi/tx/an? pb7/int1/an7/key4 pb?/ptck/an?/key3 pb?/stck/an?/key? pb4/ptpb/ptpi/an4/key1 pd?/key18 pd4/key17 pd?/key19 pe1/key?? pe3/stpb/stpi/key?4 pe?/stp/stpi/key?3 pf? pf3 pf? pf1/key?8 pf0/key?7 pe0/key?1 pd7/key?0 pc7/key1? pc?/key11 pc?/key10 pc4/key9 pc3/key8 pc?/key7 pa0/sdo/icpda/ocdsda pa?/scs/icpck/ocdsck bs66f370/bs66v370 48 lqfp-a 1 ? 3 4 ? ? 7 8 9 10 11 1? 13 14 1? 1? 17 18 19 ?0 ?1 ?? ?3 ?4 ?? ?? ?7 ?8 ?9 30 31 3? 33 34 3? 3? 4? 4?4748 3738394041 4?4344 pe?/ctck1/osc? pe4/osc1 pe7/ctp1b/key?? pe?/ctp1/key?? pa1/ctp0 pa?/ctp0b pa?/ctck0/int0 pa7 pd3/key1? pd?/key1? pd1/key14 pd0/key13 pa0/sdo/icpda/ocdsda vss pa4/sdo/xt? pa3/scs/xt1 vdd pb3/rx/an3 pb1/sck/scl/an1 pb?/ptp/ptpi/tx/an? pb7/int1/an7/key4 pb?/ptck/an?/key3 pb?/stck/an?/key? pb4/ptpb/ptpi/an4/key1 pd?/key18 pd4/key17 pd?/key19 pe1/key?? pe3/stpb/stpi/key?4 pe?/stp/stpi/key?3 pe0/key?1 pa?/scs/icpck/ocdsck pf? pf4 pf3 pf? pf1/key?8 pf0/key?7 pd7/key?0 pc3/key8 pc?/key7 pc1/key? pc0/key? pc?/key10 pc4/key9 pc?/key11 pc7/key1? pb0/vref/sdi/sda/an0
rev. 1.40 14 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f370/bs66v370 64 lqfp-a 1 ? 3 4 ? ? 7 8 9 10 11 1? 13 ?0 ?1 ?? ?3 ?4 ?? ?? ?7 ?8 ?0 ?1?? ?3 ?4 ?9 30 31 3? ???3 ?4 ???? ?7 ?8?9 14 1? 1? 43 44 4? 4? 47 48 3? 37 38 39 40 41 4? 33 34 3? 17 18 19 49?0 ?1 pf? pf3 pf? pa1/ctp0 pf4 pa?/ctp0b pa?/ctck0/int0 pa7 pd?/key18 pd4/key17 pd?/key19 pd7/key?0 pe1/key?? pe0/key?1 ph1 ph? ph0 ph3 ph? ph4 pg0/key?9 pg1/key30 pg7/key3? pg?/key3? pg?/key34 pg4/key33 pg3/key3? pg?/key31 pa?/scs/icpck/ocdsck pa0/sdo/icpda/ocdsda pa4/sdo/xt? pa3/scs/xt1 vss vdd pe?/ctck1/osc? pe4/osc1 pb3/rx/an3 pb?/ptp/ptpi/tx/an? pb0/vref/sdi/sda/an0 pb1/sck/scl/an1 vss1 vdd1 pc3/key8 pc?/key7 pc1/key? pc0/key? pc7/key1? pc?/key11 pc?/key10 pc4/key9 pb4/ptpb/ptpi/an4/key1 pb?/stck/an?/key? pb7/int1/an7/key4 pb?/ptck/an?/key3 pe3/stpb/stpi/key?4 pe?/stp/stpi/key?3 pf1/key?8 pf0/key?7 pe7/ctp1b/key?? pe?/ctp1/key?? pd3/key1? pd?/key1? pd1/key14 pd0/key13 note: t he oc dsda a nd oc dsck p ins a re t he oc ds d edicated p ins a nd o nly a vailable f or t he b s66v3x0 device which is the ocds ev chip for the bs66f3x0 device.
rev. 1.40 14 de?e??e? 1?? ?01? rev. 1.40 1 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pin descriptions with the exceptio n of the power pins and some relevant transformer control pins, all pins on these devices c an be re ferenced by t heir por t na me, e .g. p a0, p a1 e tc, whi ch re fer t o t he di gital i/ o function of the pins. however these port pins are also shared with other function such as the analog to digital converter, t imer module pins etc. t he function of each pin is listed in the following table, however the details behind how each pin is confgured is contained in other sections of the datasheet. as the pin description table shows the situation for the package with the most pins, not all pins in the table will be available on smaller package sizes. bs66f340 pad name function opt i/t o/t description pa0/sdo/ icpda/ ocdsda pa0 pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. sdo pas0 cmos spi data output icpda st cmos icp data/add ? ess pin ocdsda st cmos ocds data/add ? ess pin ? fo ? ev ? hip only. pa1/ctp0 pa1 pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. ctp0 pas0 cmos ctm0 output pa ? /ctck1/ scs/ icpck/ ocdsck pa ? pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. ctck1 pas0 st ctm1 ? lo ? k input scs pas0 ifs st cmos spi slave sele ? t icpck st cmos icp clo ? k pin ocdsck st ocds clo ? k pin ? fo ? ev ? hip only. pa3/ scs/ xt1 pa3 pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. scs pas0 ifs st cmos spi slave sele ? t xt1 pas0 lxt lxt os ? illato ? pin pa4/sdo/ xt ? pa4 pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. sdo pas1 cmos spi data output xt ? pas1 lxt lxt os ? illato ? pin pa ? /ctp0b pa ? pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. ctp0b pas1 cmos ctm0 inve ? ted output pa ? /ctck0/ int0 pa ? pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. ctck0 pas1 st ctm0 ? lo ? k input int0 pas1 integ intc0 st exte ? nal inte ?? upt 0
rev. 1.40 1 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 17 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pad name function opt i/t o/t description pa7/ctp1 pa7 pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. ctp1 pas1 cmos ctm1 output pb0/sdi/ sda/vref/ an0 pb0 pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. sdi pbs0 st spi data input sda pbs0 st nmos i ? c data line vref pbs0 an a/d conve ? te ? ? efe ? en ? e voltage output an0 pbs0 an a/d conve ? te ? analog input pb1/sck/ scl/an1 pb1 pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. sck pbs0 st cmos spi se ? ial ? lo ? k scl pbs0 st nmos i ? c ? lo ? k line an1 pbs0 an a/d conve ? te ? analog input pb ? /ptpi/ tx/ptp/an ? pb ? pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ptpi pbs0 ifs st ptm ? aptu ? e input tx pbs0 cmos uart tx se ? ial data output ptp pbs0 cmos ptm output an ? pbs0 an a/d conve ? te ? analog input pb3/rx/an3 pb3 pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. rx pbs0 st uart rx se ? ial data input an3 pbs0 an a/d conve ? te ? analog input pb4/ptpi/ ptpb/key1/ an4 pb4 pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ptpi pbs1 ifs st ptm ? aptu ? e input ptpb pbs1 cmos ptm inve ? ted output key1 pbs1 an tou ? h key input an4 pbs1 an a/d conve ? te ? analog input pb ? /stck/ key ? /an ? pb ? pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. stck pbs1 st stm ? lo ? k input key ? pbs1 an tou ? h key input an ? pbs1 an a/d conve ? te ? analog input pb ? /ptck/ key3/an ? pb ? pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ptck pbs1 st ptm ? lo ? k input key3 pbs1 an tou ? h key input an ? pbs1 an a/d conve ? te ? analog input pb7/int1/ key4/an7 pb7 pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. int1 pbs1 integ intc0 st exte ? nal inte ?? upt 1 key4 pbs1 an tou ? h key input an7 pbs1 an a/d conve ? te ? analog input
rev. 1.40 1? de?e??e? 1?? ?01? rev. 1.40 17 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pad name function opt i/t o/t description pc0/key ? pc0 pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? pcs0 an tou ? h key input pc1/key ? pc1 pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? pcs0 an tou ? h key input pc ? /key7 pc ? pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key7 pcs0 an tou ? h key input pc3/key8 pc3 pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key8 pcs0 an tou ? h key input pe0/key9 pe0 pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key9 pes0 an tou ? h key input pe1/key10 pe1 pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key10 pes0 an tou ? h key input pe ? /stpi/ stp/key11 pe ? pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. stpi pes0 ifs st stm ? aptu ? e input stp pes0 cmos stm output key11 pes0 an tou ? h key input pe3/stpi/ stpb/ key1 ? pe3 pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. stpi pes0 ifs st stm ? aptu ? e input stpb pes0 cmos stm inve ? ted output key1 ? pes0 an tou ? h key input pe4/osc1 pe4 pepu pes1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. osc1 pes1 hxt hxt os ? illato ? pin pe ? /ctp1b/ osc ? pe ? pepu pes1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ctp1b pes1 cmos ctm0 inve ? ted output osc ? pes1 hxt hxt os ? illato ? pin vdd vdd pwr positive powe ? supply vss vss pwr negative powe ? supply ? g ? ound. legend: i/t: input type; o/t: output type; opt: optional by register option; pwr: power; st: schmitt t rigger input; an: analog signal; cmos: cmos output; nmos: nmos output; hxt: high frequency crystal oscillator; lxt: low frequency crystal oscillator
rev. 1.40 18 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 19 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f350 pad name function opt i/t o/t description pa0/sdo/ icpda/ ocdsda pa0 pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. sdo pas0 cmos spi data output icpda st cmos icp data/add ? ess pin ocdsda st cmos ocds data/add ? ess pin ? fo ? ev ? hip only. pa1/ctp0 pa1 pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. ctp0 pas0 cmos ctm0 output pa ? / scs/ icpck/ ocdsck pa ? pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. scs pas0 ifs st cmos spi slave sele ? t icpck st cmos icp clo ? k pin ocdsck st ocds clo ? k pin ? fo ? ev ? hip only. pa3/ scs/xt1 pa3 pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. scs pas0 ifs st cmos spi slave sele ? t xt1 pas0 lxt lxt os ? illato ? pin pa4/sdo/xt ? pa4 pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. sdo pas1 cmos spi data output xt ? pas1 lxt lxt os ? illato ? pin pa ? /ctp0b pa ? pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. ctp0b pas1 cmos ctm0 inve ? ted output pa ? /ctck0/ int0 pa ? pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. ctck0 pas1 st ctm0 ? lo ? k input int0 pas1 integ intc0 st exte ? nal inte ?? upt 0 pa7 pa7 pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. pb0/sdi/ sda/vref/ an0 pb0 pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. sdi pbs0 st spi data input sda pbs0 st nmos i ? c data line vref pbs0 an a/d conve ? te ? ? efe ? en ? e voltage output an0 pbs0 an a/d conve ? te ? analog input
rev. 1.40 18 de?e??e? 1?? ?01? rev. 1.40 19 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pad name function opt i/t o/t description pb1/sck/ scl/an1 pb1 pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. sck pbs0 st cmos spi se ? ial ? lo ? k scl pbs0 st nmos i ? c ? lo ? k line an1 pbs0 an a/d conve ? te ? analog input pb ? /ptpi/tx/ ptp/an ? pb ? pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ptpi pbs0 ifs st ptm ? aptu ? e input tx pbs0 cmos uart tx se ? ial data output ptp pbs0 cmos ptm output an ? pbs0 an a/d conve ? te ? analog input pb3/rx/an3 pb3 pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. rx pbs0 st uart rx se ? ial data input an3 pbs0 an a/d conve ? te ? analog input pb4/ptpi/ ptpb/key1/ an4 pb4 pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ptpi pbs1 ifs st ptm ? aptu ? e input ptpb pbs1 cmos ptm inve ? ted output key1 pbs1 an tou ? h key input an4 pbs1 an a/d conve ? te ? analog input pb ? /stck/ key ? /an ? pb ? pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. stck pbs1 st stm ? lo ? k input key ? pbs1 an tou ? h key input an ? pbs1 an a/d conve ? te ? analog input pb ? /ptck/ key3/an ? pb ? pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ptck pbs1 st ptm ? lo ? k input key3 pbs1 an tou ? h key input an ? pbs1 an a/d conve ? te ? analog input pb7/int1/ key4/an7 pb7 pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. int1 pbs1 integ intc0 st exte ? nal inte ?? upt 1 key4 pbs1 an tou ? h key input an7 pbs1 an a/d conve ? te ? analog input pc0/key ? pc0 pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? pcs0 an tou ? h key input pc1/key ? pc1 pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? pcs0 an tou ? h key input pc ? /key7 pc ? pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key7 pcs0 an tou ? h key input
rev. 1.40 ? 0 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?1 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pad name function opt i/t o/t description pc3/key8 pc3 pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key8 pcs0 an tou ? h key input pc4/key9 pc4 pcpu pcs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key9 pcs1 an tou ? h key input pc ? /key10 pc ? pcpu pcs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key10 pcs1 an tou ? h key input pc ? /key11 pc ? pcpu pcs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key11 pcs1 an tou ? h key input pc7/key1 ? pc7 pcpu pcs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key1 ? pcs1 an tou ? h key input pd0/key13 pd0 pdpu pds0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key13 pds0 an tou ? h key input pd1/key14 pd1 pdpu pds0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key14 pds0 an tou ? h key input pd ? /key1 ? pd ? pdpu pds0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key1 ? pds0 an tou ? h key input pd3/key1 ? pd3 pdpu pds0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key1 ? pds0 an tou ? h key input pd4/key17 pd4 pdpu pds1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key17 pds1 an tou ? h key input pd ? /key18 pd ? pdpu pds1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key18 pds1 an tou ? h key input pd ? /key19 pd ? pdpu pds1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key19 pds1 an tou ? h key input pd7/key ? 0 pd7 pdpu pds1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? 0 pds1 an tou ? h key input pe0 pe0 pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. pe1 pe1 pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. pe ? /stpi/ stp pe ? pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. stpi pes0 ifs st stm ? aptu ? e input stp pes0 cmos stm output pe3/stpi/ stpb pe3 pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. stpi pes0 ifs st stm ? aptu ? e input stpb pes0 cmos stm inve ? ted output
rev. 1.40 ?0 de?e??e? 1?? ?01? rev. 1.40 ? 1 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pad name function opt i/t o/t description pe4/osc1 pe4 pepu pes1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. osc1 pes1 hxt hxt os ? illato ? pin pe ? /ctck1/ osc ? pe ? pepu pes1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ctck1 pes1 st ctm1 ? lo ? k input osc ? pes1 hxt hxt os ? illato ? pin pe ? /ctp1 pe ? pepu pes1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ctp1 pes1 cmos ctm1 output pe7/ctp1b pe7 pepu pes1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ctp1b pes1 cmos ctm1 inve ? ted output vdd vdd pwr positive powe ? supply vss vss pwr negative powe ? supply ? g ? ound. legend: i/t: input type; o/t: output type; opt: optional by register option; pwr: power; st: schmitt t rigger input; an: analog signal; cmos: cmos output; nmos: nmos output; hxt: high frequency crystal oscillator; lxt: low frequency crystal oscillator
rev. 1.40 ?? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?3 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver BS66F360 pad name function opt i/t o/t description pa0/sdo/ icpda/ ocdsda pa0 pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. sdo pas0 cmos spi data output icpda st cmos icp data/add ? ess pin ocdsda st cmos ocds data/add ? ess pin ? fo ? ev ? hip only. pa1/ctp0 pa1 pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. ctp0 pas0 cmos ctm0 output pa ? / scs/ icpck/ ocdsck pa ? pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. scs pas0 ifs st cmos spi slave sele ? t icpck st cmos icp clo ? k pin ocdsck st ocds clo ? k pin ? fo ? ev ? hip only. pa3/ scs/xt1 pa3 pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. scs pas0 ifs st cmos spi slave sele ? t xt1 pas0 lxt lxt os ? illato ? pin pa4/sdo/ xt ? pa4 pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. sdo pas1 cmos spi data output xt ? pas1 lxt lxt os ? illato ? pin pa ? /ctp0b pa ? pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. ctp0b pas1 cmos ctm0 inve ? ted output pa ? /ctck0/ int0 pa ? pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. ctck0 pas1 st ctm0 ? lo ? k input int0 pas1 integ intc0 st exte ? nal inte ?? upt 0 pa7 pa7 pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. pb0/sdi/ sda/vref/ an0 pb0 pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. sdi pbs0 st spi data input sda pbs0 st nmos i ? c data line vref pbs0 an a/d conve ? te ? ? efe ? en ? e voltage output an0 pbs0 an a/d conve ? te ? analog input
rev. 1.40 ?? de?e??e? 1?? ?01? rev. 1.40 ? 3 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pad name function opt i/t o/t description pb1/sck/ scl/an1 pb1 pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. sck pbs0 st cmos spi se ? ial ? lo ? k scl pbs0 st nmos i ? c ? lo ? k line an1 pbs0 an a/d conve ? te ? analog input pb ? /ptpi/tx/ ptp/an ? pb ? pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ptpi pbs0 ifs st ptm ? aptu ? e input tx pbs0 cmos uart tx se ? ial data output ptp pbs0 cmos ptm output an ? pbs0 an a/d conve ? te ? analog input pb3/rx/an3 pb3 pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. rx pbs0 st uart rx se ? ial data input an3 pbs0 an a/d conve ? te ? analog input pb4/ptpi/ ptpb/key1/ an4 pb4 pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ptpi pbs1 ifs st ptm ? aptu ? e input ptpb pbs1 cmos ptm inve ? ted output key1 pbs1 an tou ? h key input an4 pbs1 an a/d conve ? te ? analog input pb ? /stck/ key ? /an ? pb ? pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. stck pbs1 st stm ? lo ? k input key ? pbs1 an tou ? h key input an ? pbs1 an a/d conve ? te ? analog input pb ? /ptck/ key3/an ? pb ? pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ptck pbs1 st ptm ? lo ? k input key3 pbs1 an tou ? h key input an ? pbs1 an a/d conve ? te ? analog input pb7/int1/ key4/an7 pb7 pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. int1 pbs1 integ intc0 st exte ? nal inte ?? upt 1 key4 pbs1 an tou ? h key input an7 pbs1 an a/d conve ? te ? analog input pc0/key ? pc0 pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? pcs0 an tou ? h key input pc1/key ? pc1 pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? pcs0 an tou ? h key input pc ? /key7 pc ? pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key7 pcs0 an tou ? h key input pc3/key8 pc3 pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key8 pcs0 an tou ? h key input
rev. 1.40 ? 4 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pad name function opt i/t o/t description pc4/key9 pc4 pcpu pcs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key9 pcs1 an tou ? h key input pc ? /key10 pc ? pcpu pcs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key10 pcs1 an tou ? h key input pc ? /key11 pc ? pcpu pcs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key11 pcs1 an tou ? h key input pc7/key1 ? pc7 pcpu pcs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key1 ? pcs1 an tou ? h key input pd0/key13 pd0 pdpu pds0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key13 pds0 an tou ? h key input pd1/key14 pd1 pdpu pds0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key14 pds0 an tou ? h key input pd ? /key1 ? pd ? pdpu pds0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key1 ? pds0 an tou ? h key input pd3/key1 ? pd3 pdpu pds0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key1 ? pds0 an tou ? h key input pd4/key17 pd4 pdpu pds1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key17 pds1 an tou ? h key input pd ? /key18 pd ? pdpu pds1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key18 pds1 an tou ? h key input pd ? /key19 pd ? pdpu pds1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key19 pds1 an tou ? h key input pd7/key ? 0 pd7 pdpu pds1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? 0 pds1 an tou ? h key input pe0/key ? 1 pe0 pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? 1 pes0 an tou ? h key input pe1/key ?? pe1 pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ?? pes0 an tou ? h key input pe ? /stpi/ stp/key ? 3 pe ? pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. stpi pes0 ifs st stm ? aptu ? e input stp pes0 cmos stm output key ? 3 pes0 an tou ? h key input
rev. 1.40 ?4 de?e??e? 1?? ?01? rev. 1.40 ?? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pad name function opt i/t o/t description pe3/stpi/ stpb/key ? 4 pe3 pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. stpi pes0 ifs st stm ? aptu ? e input stpb pes0 cmos stm inve ? ted output key ? 4 pes0 an tou ? h key input pe4/osc1 pe4 pepu pes1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. osc1 pes1 hxt hxt os ? illato ? pin pe ? /ctck1/ osc ? pe ? pepu pes1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ctck1 pes1 st ctm1 ? lo ? k input osc ? pes1 hxt hxt os ? illato ? pin pe ? /ctp1/ key ?? pe ? pepu pes1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ctp1 pes1 cmos ctm1 output key ?? pes1 an tou ? h key input pe7/ctp1b/ key ?? pe7 pepu pes1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ctp1b pes1 cmos ctm1 inve ? ted output key ?? pes1 an tou ? h key input pf0/key ? 7 pf0 pfpu pfs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? 7 pfs0 an tou ? h key input pf1/key ? 8 pf1 pfpu pfs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? 8 pfs0 an tou ? h key input pf ? ~pf ? pfn pfpu st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. vdd vdd pwr positive powe ? supply vss vss pwr negative powe ? supply ? g ? ound. legend: i/t: input type; o/t: output type; opt: optional by register option; pwr: power; st: schmitt t rigger input; an: analog signal; cmos: cmos output; nmos: nmos output; hxt: high frequency crystal oscillator; lxt: low frequency crystal oscillator
rev. 1.40 ?? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?7 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f370 pad name function opt i/t o/t description pa0/sdo/ icpda/ ocdsda pa0 pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. sdo pas0 cmos spi data output icpda st cmos icp data/add ? ess pin ocdsda st cmos ocds data/add ? ess pin ? fo ? ev ? hip only. pa1/ctp0 pa1 pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. ctp0 pas0 cmos ctm0 output pa ? / scs/ icpck/ ocdsck pa ? pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. scs pas0 ifs st cmos spi slave sele ? t icpck st cmos icp clo ? k pin ocdsck st ocds clo ? k pin ? fo ? ev ? hip only. pa3/ scs/xt1 pa3 pawu papu pas0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. scs pas0 ifs st cmos spi slave sele ? t xt1 pas0 lxt lxt os ? illato ? pin pa4/sdo/ xt ? pa4 pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. sdo pas1 cmos spi data output xt ? pas1 lxt lxt os ? illato ? pin pa ? /ctp0b pa ? pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. ctp0b pas1 cmos ctm0 inve ? ted output pa ? /ctck0/ int0 pa ? pawu papu pas1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. ctck0 pas1 st ctm0 ? lo ? k input int0 pas1 integ intc0 st exte ? nal inte ?? upt 0 pa7 pa7 pawu papu st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up and wake-up. pb0/vref/ sdi/sda/ an0 pb0 pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. sdi pbs0 st spi data input sda pbs0 st nmos i ? c data line vref pbs0 an a/d conve ? te ? ? efe ? en ? e voltage output an0 pbs0 an a/d conve ? te ? analog input pb1/sck/ scl/an1 pb1 pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. sck pbs0 st cmos spi se ? ial ? lo ? k scl pbs0 st nmos i ? c ? lo ? k line an1 pbs0 an a/d conve ? te ? analog input
rev. 1.40 ?? de?e??e? 1?? ?01? rev. 1.40 ? 7 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pad name function opt i/t o/t description pb ? /ptpi/ tx/ptp/an ? pb ? pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ptpi pbs0 ifs st ptm ? aptu ? e input tx pbs0 cmos uart tx se ? ial data output ptp pbs0 cmos ptm output an ? pbs0 an a/d conve ? te ? analog input pb3/rx/an3 pb3 pbpu pbs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. rx pbs0 st uart rx se ? ial data input an3 pbs0 an a/d conve ? te ? analog input pb4/ptpi/ ptpb/key1/ an4 pb4 pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ptpi pbs1 ifs st ptm ? aptu ? e input ptpb pbs1 cmos ptm inve ? ted output key1 pbs1 an tou ? h key input an4 pbs1 an a/d conve ? te ? analog input pb ? /stck/ key ? /an ? pb ? pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. stck pbs1 st stm ? lo ? k input key ? pbs1 an tou ? h key input an ? pbs1 an a/d conve ? te ? analog input pb ? /ptck/ key3/an ? pb ? pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ptck pbs1 st ptm ? lo ? k input key3 pbs1 an tou ? h key input an ? pbs1 an a/d conve ? te ? analog input pb7/int1/ key4/an7 pb7 pbpu pbs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. int1 pbs1 integ intc0 st exte ? nal inte ?? upt 1 key4 pbs1 an tou ? h key input an7 pbs1 an a/d conve ? te ? analog input pc0/key ? pc0 pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? pcs0 an tou ? h key input pc1/key ? pc1 pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? pcs0 an tou ? h key input pc ? /key7 pc ? pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key7 pcs0 an tou ? h key input pc3/key8 pc3 pcpu pcs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key8 pcs0 an tou ? h key input pc4/key9 pc4 pcpu pcs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key9 pcs1 an tou ? h key input
rev. 1.40 ? 8 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?9 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pad name function opt i/t o/t description pc ? /key10 pc ? pcpu pcs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key10 pcs1 an tou ? h key input pc ? /key11 pc ? pcpu pcs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key11 pcs1 an tou ? h key input pc7/key1 ? pc7 pcpu pcs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key1 ? pcs1 an tou ? h key input pd0/key13 pd0 pdpu pds0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key13 pds0 an tou ? h key input pd1/key14 pd1 pdpu pds0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key14 pds0 an tou ? h key input pd ? /key1 ? pd ? pdpu pds0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key1 ? pds0 an tou ? h key input pd3/key1 ? pd3 pdpu pds0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key1 ? pds0 an tou ? h key input pd4/key17 pd4 pdpu pds1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key17 pds1 an tou ? h key input pd ? /key18 pd ? pdpu pds1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key18 pds1 an tou ? h key input pd ? /key19 pd ? pdpu pds1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key19 pds1 an tou ? h key input pd7/key ? 0 pd7 pdpu pds1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? 0 pds1 an tou ? h key input pe0/key ? 1 pe0 pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? 1 pes0 an tou ? h key input pe1/key ?? pe1 pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ?? pes0 an tou ? h key input pe ? /stpi/ stp/key ? 3 pe ? pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. stpi pes0 ifs st stm ? aptu ? e input stp pes0 cmos stm output key ? 3 pes0 an tou ? h key input pe3/stpi/ stpb/key ? 4 pe3 pepu pes0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. stpi pes0 ifs st stm ? aptu ? e input stpb pes0 cmos stm inve ? ted output key ? 4 pes0 an tou ? h key input
rev. 1.40 ?8 de?e??e? 1?? ?01? rev. 1.40 ? 9 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pad name function opt i/t o/t description pe4/osc1 pe4 pepu pes1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. osc1 pes1 hxt hxt os ? illato ? pin pe ? /ctck1/ osc ? pe ? pepu pes1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ctck1 pes1 st ctm1 ? lo ? k input osc ? pes1 hxt hxt os ? illato ? pin pe ? /ctp1/ key ?? pe ? pepu pes1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ctp1 pes1 cmos ctm1 output key ?? pes1 an tou ? h key input pe7/ctp1b/ key ?? pe7 pepu pes1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ctp1b pes1 cmos ctm1 inve ? ted output key ?? pes1 an tou ? h key input pf0/key ? 7 pf0 pfpu pfs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? 7 pfs0 an tou ? h key input pf1/key ? 8 pf1 pfpu pfs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? 8 pfs0 an tou ? h key input pf ? pf ? pfpu st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. pf3 pf3 pfpu st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. pf4 pf4 pfpu st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. pf ? pf ? pfpu st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. pg0/key ? 9 pg0 pgpu pgs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key ? 9 pgs0 an tou ? h key input pg1/key30 pg1 pgpu pgs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key30 pgs0 an tou ? h key input pg ? /key31 pg ? pgpu pgs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key31 pgs0 an tou ? h key input pg3/key3 ? pg3 pgpu pgs0 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key3 ? pgs0 an tou ? h key input pg4/key33 pg4 pgpu pgs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key33 pgs1 an tou ? h key input pg ? /key34 pg ? pgpu pgs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key34 pgs1 an tou ? h key input pg ? /key3 ? pg ? pgpu pgs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key3 ? pgs1 an tou ? h key input pg7/key3 ? pg7 pgpu pgs1 st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. key3 ? pgs1 an tou ? h key input ph0 ph0 phpu st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ph1 ph1 phpu st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up.
rev. 1.40 30 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 31 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pad name function opt i/t o/t description ph ? ph ? phpu st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ph3 ph3 phpu st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ph4 ph4 phpu st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. ph ? ph ? phpu st cmos gene ? al pu ? pose i/o. registe ? ena ? led pull-up. vdd ? vdd1 vdd pwr positive powe ? supply vss ? vss1 vss pwr negative powe ? supply ? g ? ound. legend: i/t: input type; o/t: output type; opt: optional by register option; pwr: power; st: schmitt t rigger input; an: analog signal; cmos: cmos output; nmos: nmos output; hxt: high frequency crystal oscillator; lxt: low frequency crystal oscillator absolute maximum ratings supply v oltage .............. .................................................................................. v ss -0.3v to v ss +6.0v input v oltage .............. .................................................................................... v ss -0.3v to v dd +0.3v storage t emperature ............... ................................................................................... -50 c to 125c operating t emperature .............. .................................................................................. -40 c to 85 c i oh t otal .............. ...................................................................................................................... -80ma i ol total ............... ...................................................................................................................... 80ma total power dissipation .............. .......................................................................................... 500mw note: these are stress ratings only . stresses exceeding the range specified under "absolute maximum ratings" may cause substantial damage to the device. functional operation of this device at other conditions beyond those listed in the specification is not implied and prolonged exposure to extreme conditions may affect device reliability. d.c. characteristics ta= ?? c symbol parameter test conditions min. typ. max. unit v dd conditions v dd ope ? ating voltage (hxt) f sys =8mhz ? . ? ? . ? v f sys =1 ? mhz ? .7 ? . ? v f sys =1 ? mhz 3.3 ? . ? v ope ? ating voltage (hirc) f sys =8mhz ? . ? ? . ? v f sys =1 ? mhz ? .7 ? . ? v f sys =1 ? mhz 3.3 ? . ? v
rev. 1.40 30 de?e??e? 1?? ?01? rev. 1.40 31 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver symbol parameter test conditions min. typ. max. unit v dd conditions i dd ope ? ating cu ?? ent (hxt) 3v f sys =f h =4mhz no load ? all pe ? iphe ? als off ? 00 7 ? 0 a ? v 1.0 1. ? ? a 3v f sys =f h =8mhz no load ? all pe ? iphe ? als off 1.0 1. ? ? a ? v ? .0 3.0 ? a 3v f sys =f h =1 ? mhz no load ? all pe ? iphe ? als off 1. ? ? .7 ? ? a ? v 3.0 4. ? ? a ? v f sys =f h =1 ? mhz ? no load ? all pe ? iphe ? als off 3. ? ? .4 ? a ope ? ating cu ?? ent (hirc) 3v f sys =f h =8mhz no load ? all pe ? iphe ? als off 0.8 1. ? ? a ? v 1. ? ? .4 ? a 3v f sys =f h =1 ? mhz no load ? all pe ? iphe ? als off 1. ? 1.8 ? a ? v ? .4 3. ? ? a ? v f sys =f h =1 ? mhz ? no load ? all pe ? iphe ? als off 3. ? 4.8 ? a ope ? ating cu ?? ent (lxt) 3v f sys =f sub =f lxt =3 ? .7 ? 8khz no load ? all pe ? iphe ? als off 10 ? 0 a ? v 30 ? 0 a ope ? ating cu ?? ent (lirc) 3v f sys =f sub =f lirc =3 ? khz no load ? all pe ? iphe ? als off 10 ? 0 a ? v 30 ? 0 a i stb stand ? y cu ?? ent (idle0 mode) 3v f sys off ? f sub on ? no load ? all pe ? iphe ? als off ? wdt ena ? led 1.3 3.0 a ? v ? .4 ? .0 a stand ? y cu ?? ent (idle1 mode) 3v f sys =1 ? mhz on ? f sub on ? no load ? all pe ? iphe ? als off ? wdt ena ? led 0.9 1.4 ? a ? v 1.4 ? .1 ? a stand ? y cu ?? ent (sleep mode) 3v f sys off ? f sub off ? no load ? all pe ? iphe ? als off ? wdt ena ? led 1. ? 1.8 a ? v 1.8 ? .7 a v il input low voltage fo ? i/o po ? ts o ? input pins ? v 0 1. ? v 0 0. ? v dd v v ih input high voltage fo ? i/o po ? ts o ? input pins ? v 3. ? ? .0 v 0.8v dd v dd v i ol sink cu ?? ent fo ? i/o pins 3v v ol =0.1v dd 17 34 ? a ? v 34 ? 8 ? a i oh sou ?? e cu ?? ent fo ? i/o pins 3v v oh =0.9v dd - ? . ? -11.0 ? a ? v -11.0 - ?? .0 ? a p ? og ? a ?? ing sou ?? e cu ?? ent fo ? i/o pins * 3v v oh =0.9v dd ? pxps[n+1:n]=00 ? x=a ? b ? c ? g o ? h ? n=0 o ? ? -1.0 - ? .0 ? a ? v - ? .0 -4.0 ? a 3v v oh =0.9v dd ? pxps[n+1:n]=01 ? x=a ? b ? c ? g o ? h ? n=0 o ? ? -1.7 ? -3. ? ? a ? v -3. ? -7.0 ? a 3v v oh =0.9v dd ? pxps[n+1:n]=10 ? x=a ? b ? c ? g o ? h ? n=0 o ? ? - ? . ? - ? .0 ? a ? v - ? .0 -10.0 ? a 3v v oh =0.9v dd ? pxps[n+1:n]=11 ? x=a ? b ? c ? g o ? h ? n=0 o ? ? - ? . ? -11.0 ? a ? v -11.0 - ?? .0 ? a r ph pull-high resistan ? e fo ? i/o po ? ts 3v ? 0 ? 0 100 k ? v 10 30 ? 0 k *note: 1. the i/o pins with p ? og ? a ?? ing sou ?? e ? u ?? ent a ? e pa1 ? pa ? ~pa7 ? pb4~pb7 ? pc0~pc3 fo ? bs ?? f340. ? . the i/o pins with p ? og ? a ?? ing sou ?? e ? u ?? ent a ? e pa1 ? pa ? ~pa7 ? pb4~pb7 ? pc0~pc7 fo ? bs ?? f3 ? 0/ bs ?? f3 ? 0/bs ?? f370 ? pg0~pg3 ? ph0~ph3 fo ? bs ?? f370.
rev. 1.40 3 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 33 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver a.c. characteristics ta= ?? c symbol parameter test condition min. typ. max. unit v dd condition f sys syste ? clo ? k (hxt) ? . ? ~ ? . ? v f sys =f hxt =8mhz 8 mhz ? .7~ ? . ? v f sys =f hxt =1 ? mhz 1 ? mhz 3.3~ ? . ? v f sys =f hxt =1 ? mhz 1 ? mhz syste ? clo ? k (hirc) ? . ? ~ ? . ? v f sys =f hirc =8mhz 8 mhz ? .7~ ? . ? v f sys =f hirc =1 ? mhz 1 ? mhz 3.3~ ? . ? v f sys =f hirc =1 ? mhz 1 ? mhz syste ? clo ? k (lxt) ? . ? ~ ? . ? v f sys =f lxt =3 ? .7 ? 8khz 3 ? .7 ? 8 khz syste ? clo ? k (lirc) ? . ? ~ ? . ? v f sys =f lirc =3 ? khz 3 ? khz f hirc high speed inte ? nal rc os ? illato ? (hirc) (1 ? mhz t ? i ? at v dd =3v) 3v ta= ?? c - ? % 1 ? + ? % mhz 3v 0.1v ta=0 c~70c - ? % 1 ? + ? % mhz ? .7v~ ? . ? v ta=0 c~70c -7% 1 ? +7% mhz ? .7v~ ? . ? v ta=-40c~8 ? c -10% 1 ? +10% mhz 3v ta= ?? c - ? 0% 8 + ? 0% mhz 3v ta= ?? c - ? 0% 1 ? + ? 0% mhz high speed inte ? nal rc os ? illato ? (hirc) (1 ? mhz t ? i ? at v dd = ? v) ? v ta= ?? c - ? % 1 ? + ? % mhz ? v 0.1v ta=0 c~70c - ? % 1 ? + ? % mhz ? .7v~ ? . ? v ta=0 c~70c -7% 1 ? +7% mhz ? .7v~ ? . ? v ta=-40c~8 ? c -10% 1 ? +10% mhz ? v ta= ?? c - ? 0% 8 + ? 0% mhz ? v ta= ?? c - ? 0% 1 ? + ? 0% mhz f lirc low speed inte ? nal rc os ? illato ? (lirc) ? v ta= ?? c -10% 3 ? +10% khz ? . ? v~ ? . ? v ta=-40c~8 ? c -40% 3 ? +40% khz t tpi stpi ? ptpi pin mini ? u ? input pulse width 0.3 s t tck ctckn ? stck ? ptck pin mini ? u ? input pulse width 0.3 s t int inte ?? upt pin mini ? u ? input pulse width 10 s t sst syste ? sta ? t-up ti ? e ? pe ? iod (wake-up f ? o ? powe ? down mode and f sys off) f sys =f h =f hxt ~f hxt / ? 4 1 ? 8 t hxt f sys =f h =f hirc ~f hirc / ? 4 1 ? t hirc f sys =f sub =f lxt 10 ? 4 t lxt f sys =f sub =f lirc ? t lirc syste ? sta ? t-up ti ? e ? pe ? iod (wake-up f ? o ? powe ? down mode and f sys on) f sys =f h ~f h / ? 4 ? f h =f hxt o ? f hirc ? t h f sys =f sub =f lxt o ? f lirc ? t sub syste ? sta ? t-up ti ? e ? pe ? iod (slow mode normal mode) (normal mode slow mode) f hxt off on (hxtf=1) 10 ? 4 t hxt f hirc off on (hircf=1) 1 ? t hirc f lxt off on (lxtf=1) 10 ? 4 t lxt syste ? sta ? t-up ti ? e ? pe ? iod (wdt ha ? dwa ? e reset) 0 t sys
rev. 1.40 3? de?e??e? 1?? ?01? rev. 1.40 33 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver symbol parameter test condition min. typ. max. unit v dd condition t rstd syste ? reset delay ti ? e (powe ? -on reset ? lvr ha ? dwa ? e ? eset ? lvrc/wdtc/rstc softwa ? e reset) ?? ? 0 100 ? s syste ? reset delay ti ? e (wdt ha ? dwa ? e reset) 8.3 1 ? .7 33.3 ? s t eerd eeprom read ti ? e 4 t sys t eewr eeprom w ? ite ti ? e 4 ? ? s note: t sys = 1/f sys a/d converter characteristics operating temperature: -40c~85c, unless otherwise specifed. symbol parameter test conditions min. typ. max. unit v dd conditions v dd ope ? ating voltage ? .7 ? . ? v v adi input voltage 0 v ref v v ref refe ? en ? e voltage ? v dd v dnl diffe ? ential non-linea ? ity 3v v ref =v dd ? t adck =0.5s or 10s 3 lsb ? v inl integ ? al non-linea ? ity 3v v ref =v dd ? t adck =0.5s or 10s 4 lsb ? v i adc additional cu ?? ent consu ? ption fo ? a/d conve ? te ? ena ? le 3v no load ? t adck =0.5s 1.0 ? .0 ? a ? v 1. ? 3.0 ? a t adck clo ? k pe ? iod antemperature sensor output 0. ? 10 s an=te ? pe ? atu ? e senso ? output 1 ? s t adc conve ? sion ti ? e (in ? luding a/d sa ? ple and hold ti ? e) antemperature sensor output 1 ? t adck an=te ? pe ? atu ? e senso ? output ?? t adck t on ? st a/d conve ? te ? on-to-sta ? t ti ? e 4 s temperature sensor electrical characteristics ta=25c, operating temperature: -40c~85c, unless otherwise specifed. symbol parameter test conditions min. typ. max. unit v dd conditions v dd ope ? ating voltage ? .7 ? . ? v v tsvref te ? pe ? atu ? e senso ? refe ? en ? e voltage 3v ta= ?? c ? t ? i ? @v dd =3v ? k_vptat=0 ? k_refo=0 - ? % ? .01 + ? % v ? v code ts a/d conve ? sion code range 3v ta= ?? c ? v ref =v tsvref ? g ? xen=1 ? an=te ? pe ? atu ? e senso ? output 1990 ??? 0 ?? 00 lsb ? v 3v ta=90c ? v ref =v tsvref ? g ? xen=1 ? an=te ? pe ? atu ? e senso ? output 3400 38 ? 0 4 ?? 0 lsb ? v 3v ta=-40c ? v ref =v tsvref ? g ? xen=1 ? an=te ? pe ? atu ? e senso ? output ?? 0 7 ? 0 99 ? lsb ? v t tss te ? pe ? atu ? e senso ? tu ? n on sta ? le ti ? e 3v ? s ? v
rev. 1.40 34 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 3? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver lvd/lvr electrical characteristics ta= ?? c symbol parameter test conditions min. typ. max. unit v dd conditions v lvr low voltage reset voltage lvr ena ? le ? voltage sele ? t ? .1v - ? % ? .1 + ? % v lvr ena ? le ? voltage sele ? t ? . ?? v ? . ?? lvr ena ? le ? voltage sele ? t 3.1 ? v 3.1 ? lvr ena ? le ? voltage sele ? t 3.8v 3.8 v lvd low voltage dete ? to ? voltage lvd ena ? le ? voltage sele ? t ? .0v - ? % ? .0 + ? % v lvd ena ? le ? voltage sele ? t ? . ? v ? . ? lvd ena ? le ? voltage sele ? t ? .4v ? .4 lvd ena ? le ? voltage sele ? t ? .7v ? .7 lvd ena ? le ? voltage sele ? t 3.0v 3.0 lvd ena ? le ? voltage sele ? t 3.3v 3.3 lvd ena ? le ? voltage sele ? t 3. ? v 3. ? lvd ena ? le ? voltage sele ? t 4.0v 4.0 v bg bandgap refe ? en ? e voltage - ? % 1.04 + ? % v i op lvd/lvr ope ? ating cu ?? ent ? v lvd/lvr ena ? le ? vbgen=0 ? 0 ?? a ? v lvd/lvr ena ? le ? vbgen=1 ?? 30 a t bgs v bg tu ? n on sta ? le ti ? e no load 1 ? 0 s t lvds lvdo sta ? le ti ? e fo ? lvr ena ? le ? vbgen=0 ? lvd offon 1 ? s fo ? lvr disa ? le ? vbgen=0 ? lvd offon 1 ? 0 s t lvr mini ? u ? low voltage width to reset 1 ? 0 ? 40 480 s t lvd mini ? u ? low voltage width to inte ?? upt ? 0 1 ? 0 ? 40 s
rev. 1.40 34 de?e??e? 1?? ?01? rev. 1.40 3 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver touch key electrical characteristics ta= ?? c touch key rc oscillator 500khz mode selected symbol parameter test conditions min. typ. max. unit v dd conditions i keyosc only senso ? (key) os ? illato ? ope ? ating cu ?? ent 3v *f senosc = ? 00khz 30 ? 0 a ? v ? 0 1 ? 0 i refosc only refe ? en ? e os ? illato ? ope ? ating cu ?? ent 3v *f refosc = ? 00khz ? mntss = 0 30 ? 0 a ? v ? 0 1 ? 0 3v *f refosc = ? 00khz ? mntss = 1 30 ? 0 a ? v ? 0 1 ? 0 c keyosc senso ? (key) os ? illato ? exte ? nal capa ? ito ? 3v *f senosc = ? 00khz 3 10 30 pf ? v ? 10 ? 0 pf c refosc refe ? en ? e os ? illato ? inte ? nal capa ? ito ? 3v *f senosc = ? 00khz 3 10 30 pf ? v ? 10 ? 0 pf f keyosc senso ? (key) os ? illato ? ope ? ating f ? equen ? y 3v * c ext =7 ? 8 ? 9 ? 10 ? 11 ? 1 ?? 13 ? 14 ? 1 ?? ? 0pf 100 ? 00 1000 khz ? v 100 ? 00 1000 khz f refosc refe ? en ? e os ? illato ? ope ? ating f ? equen ? y 3v * c int =7 ? 8 ? 9 ? 10 ? 11 ? 1 ?? 13 ? 14 ? 1 ?? ? 0pf 100 ? 00 1000 khz ? v 100 ? 00 1000 khz note: 1. f senosc = 500khz: adjust keyn external capacitor to make sure that the sensor oscillator frequency is equal to 500khz. 2. f refosc = 500khz: adjust reference oscill ator internal capacitor to make sure that the reference oscillator frequency is equal to 500khz. touch key rc oscillator 1000khz mode selected symbol parameter test conditions min. typ. max. unit v dd conditions i keyosc only senso ? (key) os ? illato ? ope ? ating cu ?? ent 3v *f senosc = 1000khz 40 80 a ? v 80 1 ? 0 i refosc only refe ? en ? e os ? illato ? ope ? ating cu ?? ent 3v *f refosc = 1000khz ? mntss = 0 40 80 a ? v 80 1 ? 0 3v *f refosc = 1000khz ? mntss = 1 40 80 a ? v 80 1 ? 0 c keyosc senso ? (key) os ? illato ? exte ? nal capa ? ito ? 3v *f senosc =1000khz 3 10 ?? pf ? v ? 10 ? 0 pf c refosc refe ? en ? e os ? illato ? inte ? nal capa ? ito ? 3v *f senosc =1000khz 3 10 ?? pf ? v ? 10 ? 0 pf f keyosc senso ? (key) os ? illato ? ope ? ating f ? equen ? y 3v * c ext =3 ? 4 ? ?? ?? 7 ? 8 ? 9 ? ? 0pf 1 ? 0 1000 ? 000 khz ? v 1 ? 0 1000 ? 000 khz f refosc refe ? en ? e os ? illato ? ope ? ating f ? equen ? y 3v * c int =3 ? 4 ? ?? ?? 7 ? 8 ? 9 ? ? 0pf 1 ? 0 1000 ? 000 khz ? v 1 ? 0 1000 ? 000 khz note: 1. f senosc = 1000khz: adjust keyn external capacitor to make sure that the sensor oscillator frequency is equal to 1000khz. 2. f refosc = 1 000khz: adj ust r eference o scillator i nternal c apacitor t o m ake sur e t hat t he r eference o scillator frequency is equal to 1000khz.
rev. 1.40 3 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 37 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver touch key rc oscillator 1500khz mode selected symbol parameter test conditions min. typ. max. unit v dd conditions i keyosc only senso ? (key) os ? illato ? ope ? ating cu ?? ent 3v *f senosc =1 ? 00khz ? 0 1 ? 0 a ? v 1 ? 0 ? 40 i refosc only refe ? en ? e os ? illato ? ope ? ating cu ?? ent 3v *f refosc =1 ? 00khz ? mntss=0 ? 0 1 ? 0 a ? v 1 ? 0 ? 40 3v *f refosc =1 ? 00khz ? mntss=1 ? 0 1 ? 0 a ? v 1 ? 0 ? 40 c keyosc senso ? (key) os ? illato ? exte ? nal capa ? ito ? 3v *f senosc = 1 ? 00khz 4 8 ? 0 pf ? v ? 10 ? 0 pf c refosc refe ? en ? e os ? illato ? inte ? nal capa ? ito ? 3v *f senosc = 1 ? 00khz 4 8 ? 0 pf ? v ? 10 ? 0 pf f keyosc senso ? (key) os ? illato ? ope ? ating f ? equen ? y 3v * c ext =3 ? 4 ? ?? ?? 7 ? 8 ? 9 ? ? 0pf 1 ? 0 1 ? 00 3000 khz ? v 1 ? 0 1 ? 00 3000 khz f refosc refe ? en ? e os ? illato ? ope ? ating f ? equen ? y 3v * c ext =3 ? 4 ? ?? ?? 7 ? 8 ? 9 ? ? 0pf 1 ? 0 1 ? 00 3000 khz ? v 1 ? 0 1 ? 00 3000 khz note: 1. f senosc =1500khz: a djust k eyn external capacitor to make s ure that the s ensor os cillator frequency is equal to 1500khz. 2. f refosc =1500khz: adjust reference oscillator internal capacitor to make sure that the reference oscillator frequency is equal to 1500khz. touch key rc oscillator 2000khz mode selected symbol parameter test conditions min. typ. max. unit v dd conditions i keyosc only senso ? (key) os ? illato ? ope ? ating cu ?? ent 3v *f senosc = ? 000khz 80 1 ? 0 a ? v 1 ? 0 3 ? 0 i refosc only refe ? en ? e os ? illato ? ope ? ating cu ?? ent 3v *f refosc = ? 000khz ? mntss=0 80 1 ? 0 a ? v 1 ? 0 3 ? 0 3v *f refosc = ? 000khz ? mntss=1 80 1 ? 0 a ? v 1 ? 0 3 ? 0 c keyosc senso ? (key) os ? illato ? exte ? nal capa ? ito ? 3v *f senosc = ? 0 00khz 4 8 ? 0 pf ? v ? 10 ? 0 pf c refosc refe ? en ? e os ? illato ? inte ? nal capa ? ito ? 3v *f senosc = ? 0 00khz 4 8 ? 0 pf ? v ? 10 ? 0 pf f keyosc senso ? (key) os ? illato ? ope ? ating f ? equen ? y 3v * c ext =3 ? 4 ? ?? ?? 7 ? 8 ? 9 ? ? 0pf 1 ? 0 ? 0 00 4000 khz ? v 1 ? 0 ? 000 4000 khz f refosc refe ? en ? e os ? illato ? ope ? ating f ? equen ? y 3v * c ext =3 ? 4 ? ?? ?? 7 ? 8 ? 9 ? ? 0pf 1 ? 0 ? 0 00 4000 khz ? v 1 ? 0 ? 000 4000 khz note: 1. f senosc =2000khz: a djust k eyn external capacitor to make s ure that the s ensor os cillator frequency is equal to 2000khz. 2. f refosc =2000khz: adjust reference oscillator internal capacitor to make sure that the reference oscillator frequency is equal to 2000khz.
rev. 1.40 3? de?e??e? 1?? ?01? rev. 1.40 37 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver power-on reset characteristics ta= ?? c symbol parameter test conditions min. typ. max. unit v dd conditions v por v dd sta ? t voltage to ensu ? e powe ? -on reset 100 ? v rr por v dd raising rate to ensu ? e powe ? -on reset 0.03 ? v/ ? s t por mini ? u ? ti ? e fo ? v dd stays at v por to ensu ? e powe ? -on reset 1 ? s             
rev. 1.40 38 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 39 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver system architecture a key factor in the high-performan ce features of the holtek range of microcontrollers is attributed to their internal system architecture. the range of devices take advantag e of the usual features found within ris c microcontrollers providing increas ed s peed of operation and enhanced performance. the pi pelining sc heme i s i mplemented i n suc h a wa y t hat i nstruction fe tching a nd i nstruction execution a re ove rlapped, he nce i nstructions a re e ffectively e xecuted i n one c ycle, wi th t he exception of branch or call instructions. an 8-bit wide alu is used in practically all instruction set operations, which carries out arithm etic operations, logic operations, rotation, increment, decrement, branch decisions, etc. the internal data path is simplifed by moving data through the accumulator and the alu. certain internal registers are implemented in the data memory and can be directly or indirectly addresse d. the simple addressi ng met hods of these registers along with additi onal architectural features ensure that a minimum of external components is required to provide a functional i/ o a nd a/ d c ontrol syst em wi th m aximum re liability a nd fe xibility. t his m akes t hese devices suitable for low-cost, high-volume production for controller applications. clocking and pipelining the main system clock, derived from either a hxt , lxt , hirc or lirc oscillator is subdivided into four internall y generated non-overlapping clocks, t1~t4. the program counter is incremented at the beginning of the t1 clock during which time a new instruction is fetched. the remaining t2~t4 clocks carry out the decoding and execution functions. in this way , one t1~t4 clock cycle forms one instruction cycle. although the fetching and execution of instructions takes place in consecutive instruction cycles, the pipelining structure of the microcontroller ensures that instructions are ef fectively executed in one instruction cycle. the exce ption to this are instructions where the content s of the program counter are changed, such as subroutine calls or jumps, in which case the instruction will take one more instruction cycle to execute. for instructions involving branches, such as jump or call instructions, two machine cycles are required to complete instruction execution. an extra cycle is required as the program takes one cycle t o frst obt ain t he a ctual j ump or c all a ddress a nd t hen a nother c ycle t o a ctually e xecute t he branch. the requirement for this extra cycle should be taken into accou nt by programmers in timing sensitive applications.                                                     
                   ?                   ?       ?  ?   ? system clocking and pipelining
rev. 1.40 38 de?e??e? 1?? ?01? rev. 1.40 39 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver                           
      ? ? ? ?     ?  ? ? ?   ?                              ? instruction fetching program counter during pro gram e xecution, t he progr am co unter i s use d t o ke ep t rack of t he a ddress of t he next instruction to be executed. it is automatically incremented by one each time an instruction is e xecuted e xcept for i nstructions, suc h a s "jmp" or "cal l" t hat de mand a j ump t o a non- consecutive program memory address. for the device whose memory capacity is greater than 8k words the program memory address may be located in a certain program memory bank w hich is selected by the program memory bank pointer bit, pbp0 or pbp1. only the lower 8 bits, known as the program counter low register, are directly addressable by the application program. when executi ng instructions re quiring jumps to non-consecutive addresses suc h as a jump instruction, a subrout ine c all, i nterrupt or re set, e tc., t he m icrocontroller m anages progra m c ontrol by loading the required address into the program counter . for conditional skip instructions, once the condition has been met, the next instruction, which has already been fetched during the present instruction execut ion, is discarded and a dummy cycle takes its place while the correct instruction is obtained. device program counter high byte low byte (pcl) bs ?? f340 pc11~pc8 pc7~pc0 bs ?? f3 ? 0 pc1 ? ~pc8 pc7~pc0 bs ?? f3 ? 0 pbp0 ? pc1 ? ~pc8 pc7~pc0 bs ?? f370 pbp0 ? pbp1 ? pc1 ? ~pc8 pc7~pc0 program counter the lower byte of the program counter , known as the program counter low register or pcl, is available for program control and is a readable and writeable register . by transferring data directly into t his r egister, a sh ort p rogram j ump c an b e e xecuted d irectly; h owever, a s o nly t his l ow b yte is available for manipulation, the jumps are limited to the present page of memory that is 256 locations. when such program jumps are executed it should also be noted that a dummy cycle will be inserted. manipulating the pcl register may cause program branching, so an extra cycle is needed to pre-fetch.
rev. 1.40 40 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 41 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver stack this is a special part of the memory which is used to save the contents of the program counter only. the stack has multiple levels and is neither part of the data nor part of the program space, and is neither readable nor writeable. the activated level is indexed by the stack pointer , and is neither readable nor writeable. at a subroutine call or interrupt acknowledge signal, the contents of the program counter are pushed onto the stack. at the end of a subroutine or an interrupt routine, signaled by a return instruction, ret or reti, the program counter is restored to its previous value from the stack. after a device reset, the stack pointer will point to the top of the stack. if the stack is full and an enabled interrupt takes place, the interrupt request fag will be recorded but the acknowledge signal will be inhibited. when the stack pointer is decremented, by ret or reti, the interrupt will be serviced. this feature prevents stack overfow allo wing the programmer to use the struct ure more easily . however , when the stack is full, a call subroutine instruction can still be execu ted which will result in a stack overfow . precautions should be taken to avoid such cases which might cause unpredictable program branching. if the stack is overfow, the frst program counter save in the stack will be lost. sta?k pointe? sta?k level ? sta?k level 1 sta?k level 3 : : : sta?k level n p?og?a? me?o?y p?og?a? counte? botto? of sta?k top of sta?k 1rwh 1 iru %?)%?) 1 iru %?) zkloh 1 iru %?) arithmetic and logic unit C alu the arith metic-logic unit or alu is a critical area of the microcontrol ler that carries out arithmetic and logic operations of the instructi on set. connected to the main micro controller data bus, the alu receives related ins truction codes and performs the required arithmetic or logical operations after which the result will be placed in the specifed register . as these alu calculation or operations may result in carry , borrow or other status changes, the status register will be correspondingly updated to refect these changes. the alu supports the following functions: ? arithmetic operations: add, addm, adc, adcm, sub, subm, sbc, sbcm, daa ladd, laddm, ladc, ladcm, lsub, lsubm, lsbc, lsbcm, ldaa ? logic operations: and, or, xor, andm, orm, xorm, cpl, cpla land, lor, lxor, landm, lorm, lxorm, lcpl, lcpla ? rotation: rra, rr, rrca, rrc, rla, rl, rlca, rlc lrra, lrr, lrrca, lrrc, lrla, lrl, lrlca, lrlc ? increment and decrement: inca, inc, deca, dec linca, linc, ldeca, ldec ? branch decision: jmp, sz, sza, snz, siz, sdz, siza, sdza, call, ret, reti lsz, lsza, lsnz, lsiz, lsdz, lsiza, lsdza
rev. 1.40 40 de?e??e? 1?? ?01? rev. 1.40 41 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver flash program memory the progra m me mory i s t he l ocation whe re t he use r c ode or progra m i s st ored. for t hese de vices series the program memory are flash type, which means it can be programmed and re-programmed a large number of times, allowing the user the convenience of code modifcation on the same device. by using the appropriate programming tools, these flash devices of fer users the fexibility to conveniently debug and develop their applications while also offering a means of feld programming and updating. device capacity banks bs ?? f340 4k 1 ? bs ?? f3 ? 0 8k 1 ? bs ?? f3 ? 0 1 ? k 1 ? 0~1 bs ?? f370 3 ? k 1 ? 0~3 structure the program memory has a capacit y of 4k16 to 32k16 bits. the program memory is addressed by the program counter and also contains data, table information and interrupt entries. t able data, which c an b e se tup i n a ny l ocation wi thin t he pr ogram me mory, i s a ddressed b y a se parate t able pointer registers. 000h initialisation ve?to? 004h fffh 1? ?its inte??upt ve?to?s look-up ta?le n00h nffh bs66f340 initialisation ve?to? 1? ?its inte??upt ve?to?s look-up ta?le bs66f350 1fffh initialisation ve?to? 1? ?its inte??upt ve?to?s look-up ta?le BS66F360 bank 1 3fffh ?000h 0?ch initialisation ve?to? 1? ?its inte??upt ve?to?s look-up ta?le bs66f370 bank 1 bank ? bank 3 4000h ?fffh ?000h 7fffh program memory structure special vectors within the program memory , certai n locations are reserved for the reset and interrupts. the location 000h is reserved for use by these devices reset for program initialisation. after a device reset is initiated, the program will jump to this location and begin execution.
rev. 1.40 4 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 43 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver look-up table any location within the program memory can be defned as a look-up table where programmers can store fxed data. t o use the look-up table, the table pointer must frst be setup by placing the address of the look up data to be retrieved in the table pointer register , tblp and tbhp . these registers defne the total address of the look-up table. after se tting u p t he t able p ointer, t he t able d ata c an b e r etrieved f rom t he pr ogram me mory u sing the "t abrd [m]" or "t abrdl [m]" instructions respectively when the memory [m] is located in sector 0. if the memory [m] is locate d in other sectors except sector 0, the data can be retrieved from the program memory using the corresponding extended t able read i nstruction such a s "l tabrd [m]" or "l tabrdl [m]" respectively . when the instruction is executed, the lower order table byte from the program memory will be transferred to the user defned data memory register [m] as specifed in the instruction. the higher order table data byte from the program memory will be transferred to the tblh special register. any unused bits in this transferred higher order byte will be read as "0". the accompanying diagram illustrates the addressing data fow of the look-up table.                            
                            
    table program example the accompanying example shows how the table pointer and table data is defined and retrieved from t he de vice. t his e xample use s ra w t able da ta l ocated i n t he l ast pa ge whi ch i s st ored t here using the o rg s tatement. the value at this o rg s tatement is " 0f00h" w hich refers to the s tart address of the last page within the 4k program memory of the bs66f340 device. the table pointer low byte register is setup here to have an initial value of "06h". this will ensure that the frst data read from the data table will be at the program memory address "0f06h" or 6 locations after the start of the last page. note that the value for the table pointer is referenced to the frst address of the present page pointed by the tbhp register if the "t abrd [m]" instruction is being used. the high byte o f t he t able d ata wh ich i n t his c ase i s e qual t o z ero wi ll b e t ransferred t o t he t blh r egister automatically when the "tabrd [m] instruction is executed. because the tblh register is a read/write register and can be restored, care should be taken to ensure its protection if both the main routine and interrupt s ervice routine us e table read instructions. if using the table read instructions, the interrupt service routines may change the value of the tblh and subsequently cause errors if used again by the main routine. as a rule it is recommended that simultaneous use of the table read instructions should be avoided. however , in situations where simultaneous use cannot be avoided, the interrupts should be disabled prior to the execution of any main routine table-read instructions. note that all table related instructions require two instruction cycles to complete their operation.
rev. 1.40 4? de?e??e? 1?? ?01? rev. 1.40 43 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver table read program example tempreg1 db ? ; temporary register #1 tempreg2 db ? ; temporary register #2 : mov a ,06h ; initialise low table pointer - note that this address is referenced mov t blp,a ; to the last page or the page that tbhp pointed mov a ,0fh ; initialise high table pointer mov tbhp,a : tabrd t empreg1 ; transfers value in table referenced by table pointer data at program ; memory address "0f06h" transferred to tempreg1 and tblh dec t blp ; reduce value of table pointer by one tabrd t empreg2 ; transfers value in table referenced by table pointer data at program ; memory address "0f05h" transferred to tempreg2 and tblh in this ; example the data "1ah" is transferred to tempreg1 and data "0fh" to ; register tempreg2 : org 0 f00h ; sets initial address of program memory dc 00 ah, 00bh, 00ch, 00dh, 00eh, 00fh, 01ah, 01bh : in circuit programming C icp the p rovision o f fl ash t ype pr ogram me mory p rovides t he u ser wi th a m eans o f c onvenient a nd easy upgrades and modifcations to their programs on the same device. as an additional convenience, holtek has provided a means of programming the microcontroller in- circuit using a 4-pin interface. this provides manufacturers with the possibility of manufacturing their circuit boards complete with a programmed or un-programmed microcontroller , and then programming o r u pgrading t he p rogram a t a l ater st age. t his enables product m anufacturers to e asily keep thei r manufa ctured products supplied with the latest program releases without removal and re- insertion of the device. holtek writer pins mcu programming pins pin description icpda pa0 p ? og ? a ?? ing se ? ial data/add ? ess icpck pa ? p ? og ? a ?? ing clo ? k vdd vdd powe ? supply vss vss g ? ound the program memory and eeprom data memory can be programmed serially in-circuit using this 4-wire interface. data is downloaded and uploaded serially on a single pin with an additional line for the clock. t wo additional lines are required for the power supply . the technical details regarding the in-cir cuit programming of the device are beyond the scope of this document and will be supplied in supplementary literature. during the programming process, the user must take care of the icpda and icpck pins for data and clock programming purposes to ensure that no other outputs are connected to these two pins.
rev. 1.40 44 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 4? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver                        
                        note: * may be resistor or capacitor . the resistance of * must be greate r than 1k or the capacitance of * must be less than 1nf. on-chip debug support C ocds there is an ev chip named bs66v 3x0 w hich is us ed to emulate the real mcu device named bs66f3x0. the ev chip device also provides the "on-chip debug" function to debug the real mcu device during development process. the ev chip and real mcu devices, bs66v3x0 and bs66f3x0, are almost functional compatible except the "on-chip debug" function. users can use the ev chip device to emulate the real mcu device behaviors by connecting the ocdsda and ocdsck pins to t he ho ltek ht -ide d evelopment t ools. t he oc dsda p in i s t he oc ds da ta/address i nput/output pin whi le t he ocdsck pi n i s t he ocds c lock i nput pi n. w hen use rs use t he e v c hip de vice for debugging, the corresponding pin functions shared with the ocdsda and ocdsck pins in the real mcu device will have no ef fect in the ev chip. however , the two ocds pins which are pin-shared with the icp programming pins are still used as the flash memory programming pins for icp . for more detailed ocds information, refer to the corresponding document named "holtek e-link for 8-bit mcu ocds users guide". holtek e-link pins ev chip ocds pins pin description ocdsda ocdsda on-chip de ? ug suppo ? t data/add ? ess input/output ocdsck ocdsck on-chip de ? ug suppo ? t clo ? k input vdd vdd powe ? supply vss vss g ? ound
rev. 1.40 44 de?e??e? 1?? ?01? rev. 1.40 4 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver in application programming C iap these devices of fer iap function to update data or application program to fash rom. users can defne any rom location for iap , but there are some features which user must notice in using iap function. note that the bs66f340 device supports the "block erase" function instead of the "page erase" function. bs66f340 confgurations bs66f350 confgurations BS66F360/370 confgurations e ? ase blo ? k ??? wo ? ds / ? lo ? k e ? ase page 3 ? wo ? ds / page e ? ase page ? 4 wo ? ds / page w ? iting wo ? d 4 wo ? ds / ti ? e w ? iting wo ? d 3 ? wo ? ds / ti ? e w ? iting wo ? d ? 4 wo ? ds / ti ? e reading wo ? d 1 wo ? d / ti ? e reading wo ? d 1 wo ? d / ti ? e reading wo ? d 1 wo ? d / ti ? e in application programming control registers the address register , f arl and f arh, the data registers, fd0l/fd0h, fd1l/fd1h, fd2l/fd2h and fd3l/fd3h, and the control registers, fc0, fc1 and fc2, are the corresponding flash access registers located in data memory sector 0 for iap . if using the indirect addressing method to access the fc0, fc1 and fc2 regis ters, all read and w rite operations to the regis ters must be performed using the indirect addressing register , iar1 or iar2, and the memory pointer pair , mp1l/mp1h or mp 2l/mp2h. because the fc0, fc1 and fc2 control regis ters are located at the addres s of 50h~52h in data memory sector 0, the desired value ranged from 50h to 52h must frst be written into the mp1l or mp2l memory pointer low byte and the value "00h" must also be written into the mp1h or mp2h memory pointer high byte. register name bit 7 6 5 4 3 2 1 0 fc0 cfwen fmod ? fmod1 fmod0 fwpen fwt frden frd fc1 d7 d ? d ? d4 d3 d ? d1 d0 fc ? (bs ?? f3 ? 0/3 ? 0/370) clwb farl a7 a ? a ? a4 a3 a ? a1 a0 farh (bs ?? f340) a11 a10 a9 a8 farh (bs ?? f3 ? 0) a1 ? a11 a10 a9 a8 farh (bs ?? f3 ? 0) a13 a1 ? a11 a10 a9 a8 farh (bs ?? f370) a14 a13 a1 ? a11 a10 a9 a8 fd0l d7 d ? d ? d4 d3 d ? d1 d0 fd0h d1 ? d14 d13 d1 ? d11 d10 d9 d8 fd1l d7 d ? d ? d4 d3 d ? d1 d0 fd1h d1 ? d14 d13 d1 ? d11 d10 d9 d8 fd ? l d7 d ? d ? d4 d3 d ? d1 d0 fd ? h d1 ? d14 d13 d1 ? d11 d10 d9 d8 fd3l d7 d ? d ? d4 d3 d ? d1 d0 fd3h d1 ? d14 d13 d1 ? d11 d10 d9 d8 iap registers list
rev. 1.40 4 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 47 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? fc0 register bit 7 6 5 4 3 2 1 0 na ? e cfwen fmod ? fmod1 fmod0 fwpen fwt frden frd r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 1 1 1 0 0 0 0 bit 7 cfwen : flash memory w rite enable control 0: flash memory write function is disabled 1: flash memory write function has been successfully enabled when this bit is cleared to 0 by application program, the flash memory write function is disabled. note that writing a "1" into this bit results in no action. this bit is used to indicate that the flash memory write function status. when this bit is set to 1 by hardware, it means that the f lash memory w rite function is enabled s uccessfully. otherwise, the flash memory write function is disabled as the bit content is zero. bit 6~4 fmod2~fmod0 : mode selection 000: w rite program memory 001: block/page erase program memory 010: reserved 011: read program memory 10x: reserved 110: fwen mode C flash memory w rite function enabled mode 111: reserved when these bits are set to "001", the "block erase" mode is selected for bs66f340 while the "page erase" mode is selected for bs66f350/BS66F360/bs66f370. bit 3 fwpen : flash memory w rite procedure enable control 0: disable 1: enable when this bit is set to 1 and the fmod feld is set to "1 10", the iap cont roller will execute the "flash memory write function enable" procedure. once the flash memory write func tion i s suc cessfully e nabled, i t i s not ne cessary t o set t he fw pen bi t a ny more. bit 2 fwt : flash memory w rite initiate control 0: do not initiate flash memory write or flash memory write process is completed 1: initiate flash memory write process this bit is set by software and cleared by hardware when the flash memory write process is completed. bit 1 frden : flash memory read enable control 0: flash memory read disable 1: flash memory read enable bit 0 frd : flash memory read initiate control 0: do not initiate flash memory read or flash memory read process is completed 1: initiate flash memory read process this bi t i s se t by soft ware a nd c leared by hardware whe n t he fl ash m emory rea d process is completed. ? fc1 register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 d7~d0 : whole chip reset pattern when use r wri tes a spe cific va lue of "55h" t o t his re gister, i t wi ll ge nerate a re set signal to reset whole chip.
rev. 1.40 4? de?e??e? 1?? ?01? rev. 1.40 47 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? fc2 register C bs66f350/BS66F360/bs66f370 bit 7 6 5 4 3 2 1 0 na ? e clwb r/w r/w por 0 bit 7~1 unimplemented, read as 0. bit 0 clwb : flash memory w rite buffer clear control 0: do n ot i nitiate w rite b uffer c lear p rocess o r w rite b uffer c lear p rocess i s c ompleted 1: initiate w rite buffer clear process this bi t i s se t by soft ware a nd c leared by ha rdware whe n t he w rite buf fer cl ear process is completed. ? farl register bit 7 6 5 4 3 2 1 0 na ? e a7 a ? a ? a4 a3 a ? a1 a0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 flash memory address bit 7 ~ bit 0 ? farh register C bs66f340 bit 7 6 5 4 3 2 1 0 na ? e a11 a10 a9 a8 r/w r/w r/w r/w r/w por 0 0 0 0 bit 7~4 unimplemented, read as 0. bit 3~0 flash memory address bit 11 ~ bit 8 ? farh register C bs66f350 bit 7 6 5 4 3 2 1 0 na ? e a1 ? a11 a10 a9 a8 r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 bit 7~5 unimplemented, read as 0. bit 4~0 flash memory address bit 12 ~ bit 8 ? farh register C BS66F360 bit 7 6 5 4 3 2 1 0 na ? e a13 a1 ? a11 a10 a9 a8 r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 bit 7~6 unimplemented, read as 0. bit 5~0 flash memory address bit 13 ~ bit 8 ? farh register C bs66f370 bit 7 6 5 4 3 2 1 0 na ? e a14 a13 a1 ? a11 a10 a9 a8 r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 bit 7 unimplemented, read as 0. bit 6~0 flash memory address bit 14 ~ bit 8
rev. 1.40 48 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 49 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? fd0l register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 the frst flash memory data bit 7 ~ bit 0 ? fd0h register bit 7 6 5 4 3 2 1 0 na ? e d1 ? d14 d13 d1 ? d11 d10 d9 d8 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 the frst flash memory data bit 15 ~ bit 8 ? fd1l register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 the second flash memory data bit 7 ~ bit 0 ? fd1h register bit 7 6 5 4 3 2 1 0 na ? e d1 ? d14 d13 d1 ? d11 d10 d9 d8 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 the second flash memory data bit 15 ~ bit 8 ? fd2l register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 the third flash memory data bit 7 ~ bit 0 ? fd2h register bit 7 6 5 4 3 2 1 0 na ? e d1 ? d14 d13 d1 ? d11 d10 d9 d8 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 the third flash memory data bit 15 ~ bit 8 ? fd3l register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 the fourth flash memory data bit 7 ~ bit 0
rev. 1.40 48 de?e??e? 1?? ?01? rev. 1.40 49 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? fd3h register bit 7 6 5 4 3 2 1 0 na ? e d1 ? d14 d13 d1 ? d11 d10 d9 d8 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 the fourth flash memory data bit 15 ~ bit 8 flash memory write function enable procedure in orde r t o a llow use rs t o c hange t he fl ash m emory da ta t hrough t he iap c ontrol re gisters, use rs must frst enable the flash memory write operation by the following procedure: 1. w rite "110" into the fmod2~fmod0 bits to select the fwen mode. 2. set the fwpen bit to "1". the step 1 and step 2 can be executed simultaneously. 3. the pattern data with a sequence of 00h, 04h, 0dh, 09h, c3h and 40h must be written into the fd1l, fd1h, fd2l, fd2h, fd3l and fd3h registers respectively. 4. a counter with a time-out period of 300s will be activated to allow users writing the correct pattern data into the fd1l/fd1h~fd3l/fd3h register pairs. the counter clock is derived from lirc oscillator. 5. if the counter overfows or the pattern data is incorrect, the flash memory write operation will not be enabled and users must again repeat the above procedure. t hen the fwpen bit will automatically be cleared to 0 by hardware. 6. if the pattern data is correct before the counter overfows, the flash memory write operation will be enabled and the fwpen bit will automatically be cleared to 0 by hardware. the cfwen bit will also be set to 1 by hardware to indicate that the flash memory write operation is successfully enabled. 7. once the flash memory write operation is enabled, the user can change the flash rom data through the flash control register. 8. t o disable the flash memory write operation, the user can clear the cfwen bit to 0. flash me?o?y w?ite fun?tion ena?le p?o?edu?e set fmod [?:0 ] = 110 & fwpen =1 sele?t fwen ?ode & sta?t flash w?ite ha?dwa?e a?tivate a ?ounte? w?tie the following patte?n to flash data ?egiste?s fd 1l = 00h ? fd 1 h = 04h fd ?l = 0 dh ? fd ? h = 09h fd 3l = c3 h ? fd 3 h = 40h su??ess end yes failed cfwen =0 cfwen = 1 no is ?ounte? ove?flow ? no fwpen =0 is patte?n ?o??e?t ? yes flash memory write function enable procedure
rev. 1.40 ? 0 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?1 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver flash memory read/write procedure after the flash memory write functi on is successfully enabled through the preceding iap procedure, users must fi rst erase the corresponding flash memory bl ock or pa ge and then initiate the flash memory writ e operat ion. for t he bs66f340 devi ce t he number of t he bloc k erase operat ion i s 256 words per block, the available block erase address is only specifed by f arh register and the content in the f arl register is not used to specify the block address. for the bs66f350, BS66F360 and bs66f370 devices the number of the page erase operation is 32, 64 and 64 words per page respectively, the available page erase address is specifed by f arh register and the content of f arl [7:5] and farl [7:6] bit feld respectively. erase block farh [3:0] farl [7:0] 0 0000 xxxx xxxx 1 0001 xxxx xxxx ? 0010 xxxx xxxx 3 0011 xxxx xxxx 4 0100 xxxx xxxx ? 0101 xxxx xxxx ? 0110 xxxx xxxx 7 0111 xxxx xxxx 8 1000 xxxx xxxx 9 1001 xxxx xxxx 10 1010 xxxx xxxx 11 1011 xxxx xxxx 1 ? 1100 xxxx xxxx 13 1101 xxxx xxxx 14 1110 xxxx xxxx 1 ? 1111 xxxx xxxx "x": dont ? a ? e bs66f340 erase block number and selection erase page farh farl [7:5] farl [4:0] 0 0000 0000 000 x xxxx 1 0000 0000 001 x xxxx ? 0000 0000 010 x xxxx 3 0000 0000 011 x xxxx 4 0000 0000 100 x xxxx ? 0000 0000 101 x xxxx ? 0000 0000 110 x xxxx 7 0000 0000 111 x xxxx 8 0000 0001 000 x xxxx 9 0000 0001 001 x xxxx : : : : 1 ?? 0000 1111 110 x xxxx 1 ? 7 0000 1111 111 x xxxx 1 ? 8 0001 0000 000 x xxxx 1 ? 9 0001 0000 001 x xxxx : : : : ?? 4 0001 1111 110 x xxxx ??? 0001 1111 111 x xxxx "x": dont ? a ? e bs66f350 erase page number and selection
rev. 1.40 ?0 de?e??e? 1?? ?01? rev. 1.40 ? 1 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver erase page farh farl [7:6] farl [5:0] 0 0000 0000 00 xx xxxx 1 0000 0000 01 xx xxxx ? 0000 0000 10 xx xxxx 3 0000 0000 11 xx xxxx 4 0000 0001 00 xx xxxx ? 0000 0001 01 xx xxxx : : : : 1 ?? 0001 1111 10 xx xxxx 1 ? 7 0001 1111 11 xx xxxx 1 ? 8 0010 0000 00 xx xxxx 1 ? 9 0010 0000 01 xx xxxx : : : : ?? 4 0011 1111 10 xx xxxx ??? 0011 1111 11 xx xxxx "x": dont ? a ? e BS66F360 erase page number and selection erase page farh farl [7:6] farl [5:0] 0 0000 0000 00 xx xxxx 1 0000 0000 01 xx xxxx ? 0000 0000 10 xx xxxx 3 0000 0000 11 xx xxxx 4 0000 0001 00 xx xxxx ? 0000 0001 01 xx xxxx : : : : : : : : 1 ?? 0001 1111 10 xx xxxx 1 ? 7 0001 1111 11 xx xxxx 1 ? 8 0010 0000 00 xx xxxx 1 ? 9 0010 0000 01 xx xxxx : : : : : : : : ?? 4 0011 1111 10 xx xxxx ??? 0011 1111 11 xx xxxx ??? 0100 0000 00 xx xxxx ?? 7 0100 0000 01 xx xxxx : : : : : : : : ? 10 0111 1111 10 xx xxxx ? 11 0111 1111 11 xx xxxx "x": dont ? a ? e bs66f370 erase page number and selection
rev. 1.40 ?? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?3 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver read flash me?o?y clea? f rde n ?it end read finish ? yes no set f mod [?:0]= 011 & frden =1 set flash add?ess ?egiste?s farh =xxh ? farl =xxh frd = 0 ? yes no read data value : fd 0l=xxh ? fd 0h=xxh set frd =1 read flash memory procedure
rev. 1.40 ?? de?e??e? 1?? ?01? rev. 1.40 ? 3 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver w?ite flash me?o?y flash memory write function enable procedure set fwt=1 fwt=0 ? yes no set blo?k e?ase add?ess: farh/farl set fmod [?:0]=001 & fwt=1 sele?t blo?k e?ase ?ode & initiate w?ite ope?ation fwt=0 ? yes no end w?ite finish ? yes no clea? cfwen=0 set fmod [?:0]=000 sele?t w?ite flash mode set w?ite sta?ting add?ess: farh/farl w?ite data to data ?egiste?: fd0l/fd0h? fd1l/fd1h? fd?l/fd?h? fd3l/fd3h? write flash memory procedure C bs66f340
rev. 1.40 ? 4 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver w?ite flash me?o?y flash memory write function enable procedure set fwt=1 fwt=0 ? yes no set page e?ase add?ess: farh/farl set fmod [?:0]=001 & fwt=1 sele?t page e?ase ?ode & initiate w?ite ope?ation fwt=0 ? yes no end w?ite finish ? yes no clea? cfwen=0 set fmod [?:0]=000 sele?t w?ite flash mode set w?ite sta?ting add?ess: farh/farl w?ite data to data ?egiste?: fd0l/fd0h page data w?ite finish yes no write flash memory procedure C bs66f350/BS66F360/bs66f370 note: when the fwt or frd bit is set to 1, the mcu is stopped.
rev. 1.40 ?4 de?e??e? 1?? ?01? rev. 1.40 ?? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver data memory the dat a mem ory is an 8-bit wide ram inte rnal me mory and is the locat ion where te mporary information is stored. divided into two types, the frst of data memory is an area of ram where special function registers are located. these registers have fxed locations and are necessary for correct operation of the device. many of these registers can be read from and written to directly under program control, however, some remain p rotected f rom u ser m anipulation. t he se cond a rea o f da ta me mory i s r eserved f or g eneral purpose use. all locations within this area are read and write accessible under program control. switching betwee n the dif ferent data memory sectors is achieved by properly setting the memory pointers to correct value. structure the da ta me mory i s subdi vided i nto se veral se ctors, a ll of wh ich a re i mplemented i n 8-b it wi de memory. each of the data memory sectors is categorized into two types, the special purpose data memory and the general purpose data memory. the address range of the special purpose data memory for the device is from 00h to 7fh. the general purpose data memory address range is from 80h to ffh except the t ouch key module data memory . the t ouch key modul data memory is located in sector 5 and sector 6 respectively with a start address of 00h. device special purpose data memory general purpose data memory touch key module data memory located sectors capacity sector : address sector : address bs ?? f340 0 ? 1 ? 1 ? x 8 0: 80h~ffh 1: 80h~ffh ? : 80h~ffh 3: 80h~ffh ? : 00h~17h ? : 00h~17h bs ?? f3 ? 0 0 ? 1 7 ? 8 x 8 0: 80h~ffh 1: 80h~ffh : ? : 80h~ffh ? : 00h~ ? 7h ? : 00h~ ? 7h bs ?? f3 ? 0 0 ? 1 10 ? 4 x 8 0: 80h~ffh 1: 80h~ffh : 7: 80h~ffh ? : 00h~37h ? : 00h~37h bs ?? f370 0 ? 1 1 ? 3 ? x 8 0: 80h~ffh 1: 80h~ffh : 11: 80h~ffh ? : 00h~47h ? : 00h~47h data memory summary
rev. 1.40 ?? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?7 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver 00h 7fh 80h ffh spe?ial pu?pose data me?o?y gene?al pu?pose data me?o?y se?to? 0 se?to? 1 se?to? n (se?to? 0 ~ se?to? 1) (se?to? 0 ~ se?to? n) note: n=3 fo? bs??f340; n=? fo? bs??f3?0; n=7 fo? bs??f3?0; tou?h key module data me?o?y (se?to? ?~se?to? ?) n=11 fo? bs??f370 data memory structure data memory addressing for these devices that support the extended instructions, there is no bank pointer for data memory . the bank pointer , pbp , is only avai lable for program memory . for data memory the desired sector is pointed by the mp1h or mp2h register and the certain data memory address in the selected sector is specifed by the mp1l or mp2l register when using indirect addressing access. direct addressing can be used in all sectors using the corresponding instruction which can address all available data memory space. for the accessed data memory which is located in any data memory s ectors except s ector 0, the extended ins tructions can be us ed to acces s the data memory instead o f u sing t he i ndirect a ddressing a ccess. t he m ain d ifference b etween st andard i nstructions and exten ded instructions is that the data memory address "m" in the extended instructions can be from 10 bits to 1 1 bits depending upon which device is selected, the high byte indicates a sector and the low byte indicates a specifc address. general purpose data memory all microcontroller programs require an area of read/write memory where temporary data can be stored and retrieve d for use later . it is this area of ram memory that is known as general purpose data memory . this area of data memory is fully accessible by the user programing for both reading and wr iting o perations. b y u sing t he b it o peration i nstructions i ndividual b its c an b e se t o r r eset under program control giving the user a lar ge range of fexibility for bit manipulation in the data memory. special purpose data memory this area of data memory is where registers, necessary for the correct operation of the microcontroller, are stored. most of the registers are both readable and writeable but some are protected and are readable only , the details of which are located under the relevant special function register section. note that for locat ions that are unused, any read instruction to these addresses will return the value "00h".
rev. 1.40 ?? de?e??e? 1?? ?01? rev. 1.40 ? 7 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver 00h iar0 01h mp0 0?h iar1 03h mp1l 04h 0?h acc 0?h pcl 07h tblp 08h tblh 09h tbhp 0ah status 0bh 0ch lvdc 0dh integ 0eh 0fh 10h intc0 11h 1?h 19h papu 18h pawu 1bh 1ah 1dh 1ch 1fh pa pac 13h 14h mfi0 1?h mfi1 1?h 17h : unused? ?ead as 00h mfi? wdtc tb0c ctm0c0 ctm0c1 ctm0dl ctm0dh ctm0al ctm0ah ?0h ?1h ??h ?9h ?8h ?bh ?ah ?dh ?ch ?fh ?eh ?3h ?4h ??h ??h ?7h eea 40h 41h 4?h 43h 44h 4?h 4?h 47h 48h 49h 4ah 4bh 4ch 4dh 4eh 4fh ?0h ?1h ??h ?3h ?4h mfi3 lvrc eed 1eh eec se?to? 0 se?to? 0 se?to? 1 ??h ??h ?0h ?1h ??h ?3h ?4h ??h ??h ?7h ?8h ?9h ?ah ?bh ?ch ?dh ?eh ?fh 70h 30h 31h 3?h 38h 3ch 33h 34h 3?h 3?h 37h 3bh 39h 3ah 71h 7?h 73h 74h 7?h 7?h 7bh pbc pbpu pb 3dh 3fh 3eh 7fh mp1h iar? mp?l mp?h pscr0 tb1c scc hxtc lxtc rstc pcc pcpu pc ?7h ?8h ?9h ?ah ?bh ?ch ?dh ?eh ?fh simtoc simc0 simc1 simd sima/simc? fc0 fc1 farl farh fd0l fd0h fd1l fd1h fd?l fd?h fd3l fd3h se?to? 1 hircc rstfc intc1 intc? adrl adcr0 adrh adcr1 pscr1 sledc ptmc0 ptmc1 ptmdl ptmdh ptmal ptmah ptmrpl ptmrph stmc0 stmc1 stmdl stmdh stmal stmah stmrp ctm1c0 ctm1c1 ctm1dl ctm1dh ctm1al ctm1ah tsc0 tsc1 tsc? tsc3 pe pec pepu 77h 78h usr ucr1 ucr? txr_rxr brg 79h 7ah tktmr tkc0 tk1?dl tk1?dh tkc1 tkm01?dl tkm01?dh tkm0rol tkm0roh tkm0c0 tkm0c1 tkm0c? tkm11?dl tkm11?dh tkm1rol tkm1roh tkm1c0 tkm1c1 tkm1c? tkm?1?dl tkm?1?dh tkm?rol tkm?roh tkm?c0 tkm?c1 tkm?c? ifs pas0 pas1 pbs0 pbs1 pcs0 pes0 pes1 special purpose data memory structure C bs66f340
rev. 1.40 ? 8 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?9 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver 00h iar0 01h mp0 0?h iar1 03h mp1l 04h 0?h acc 0?h pcl 07h tblp 08h tblh 09h tbhp 0ah status 0bh 0ch lvdc 0dh integ 0eh 0fh 10h intc0 11h 1?h 19h papu 18h pawu 1bh 1ah 1dh 1ch 1fh pa pac 13h 14h mfi0 1?h mfi1 1?h 17h : unused? ?ead as 00h mfi? wdtc tb0c ctm0c0 ctm0c1 ctm0dl ctm0dh ctm0al ctm0ah ?0h ?1h ??h ?9h ?8h ?bh ?ah ?dh ?ch ?fh ?eh ?3h ?4h ??h ??h ?7h eea 40h 41h 4?h 43h 44h 4?h 4?h 47h 48h 49h 4ah 4bh 4ch 4dh 4eh 4fh ?0h ?1h ??h ?3h ?4h mfi3 lvrc eed 1eh eec se?to? 0 se?to? 0 se?to? 1 ??h ??h ?0h ?1h ??h ?3h ?4h ??h ??h ?7h ?8h ?9h ?ah ?bh ?ch ?dh ?eh ?fh 70h 30h 31h 3?h 38h 3ch 33h 34h 3?h 3?h 37h 3bh 39h 3ah 71h 7?h 73h 74h 7?h 7?h 7bh pbc pbpu pb 3dh 3fh 3eh 7fh mp1h iar? mp?l mp?h pscr0 tb1c scc hxtc lxtc rstc pcc pcpu pc ?7h ?8h ?9h ?ah ?bh ?ch ?dh ?eh ?fh simtoc simc0 simc1 simd sima/simc? fc0 fc1 farl farh fd0l fd0h fd1l fd1h fd?l fd?h fd3l fd3h se?to? 1 hircc rstfc intc1 intc? pd pdc pdpu adrl adcr0 adrh adcr1 pscr1 sldec ptmc0 ptmc1 ptmdl ptmdh ptmal ptmah ptmrpl ptmrph stmc0 stmc1 stmdl stmdh stmal stmah stmrp ctm1c0 ctm1c1 ctm1dl ctm1dh ctm1al ctm1ah tsc0 tsc1 tsc? tsc3 pe pec pepu 77h 78h usr ucr1 ucr? txr_rxr brg 79h 7ah tktmr tkc0 tk1?dl tk1?dh tkc1 tkm01?dl tkm01?dh tkm0rol tkm0roh tkm0c0 tkm0c1 tkm0c? tkm11?dl tkm11?dh tkm1rol tkm1roh tkm1c0 tkm1c1 tkm1c? tkm?1?dl tkm?1?dh tkm?rol tkm?roh tkm?c0 tkm?c1 tkm?c? tkm31?dl tkm31?dh tkm3rol tkm3roh tkm3c0 tkm3c1 tkm3c? ifs pas0 pas1 pbs0 pbs1 pcs0 pds1 pes0 pes1 fc? tkm41?dl tkm41?dh tkm4rol tkm4roh tkm4c0 tkm4c1 tkm4c? pcs1 pds0 special purpose data memory structure C bs66f350
rev. 1.40 ?8 de?e??e? 1?? ?01? rev. 1.40 ? 9 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver 00h iar0 01h mp0 0?h iar1 03h mp1l 04h 0?h acc 0?h pcl 07h tblp 08h tblh 09h tbhp 0ah status 0bh 0ch lvdc 0dh integ 0eh 0fh 10h intc0 11h 1?h 19h papu 18h pawu 1bh 1ah 1dh 1ch 1fh pa pac 13h 14h mfi0 1?h mfi1 1?h 17h : unused? ?ead as 00h mfi? wdtc tb0c ctm0c0 ctm0c1 ctm0dl ctm0dh ctm0al ctm0ah ?0h ?1h ??h ?9h ?8h ?bh ?ah ?dh ?ch ?fh ?eh ?3h ?4h ??h ??h ?7h eea 40h 41h 4?h 43h 44h 4?h 4?h 47h 48h 49h 4ah 4bh 4ch 4dh 4eh 4fh ?0h ?1h ??h ?3h ?4h mfi3 lvrc eed 1eh eec se?to? 0 se?to? 0 se?to? 1 ??h ??h ?0h ?1h ??h ?3h ?4h ??h ??h ?7h ?8h ?9h ?ah ?bh ?ch ?dh ?eh ?fh 70h 30h 31h 3?h 38h 3ch 33h 34h 3?h 3?h 37h 3bh 39h 3ah 71h 7?h 73h 74h 7?h 7?h 7bh pbc pbpu pb 3dh 3fh 3eh 7fh mp1h iar? mp?l mp?h pscr0 tb1c scc hxtc lxtc rstc pcc pcpu pc ?7h ?8h ?9h ?ah ?bh ?ch ?dh ?eh ?fh simtoc simc0 simc1 simd sima/simc? fc0 fc1 farl farh fd0l fd0h fd1l fd1h fd?l fd?h fd3l fd3h se?to? 1 hircc rstfc intc1 intc? pd pdc pdpu adrl adcr0 adrh adcr1 pscr1 sledc ptmc0 ptmc1 ptmdl ptmdh ptmal ptmah ptmrpl ptmrph stmc0 stmc1 stmdl stmdh stmal stmah stmrp ctm1c0 ctm1c1 ctm1dl ctm1dh ctm1al ctm1ah tsc0 tsc1 tsc? tsc3 pe pec pepu 77h 78h usr ucr1 ucr? txr_rxr brg 79h 7ah tktmr tkc0 tk1?dl tk1?dh tkc1 tkm01?dl tkm01?dh tkm0rol tkm0roh tkm0c0 tkm0c1 tkm0c? tkm11?dl tkm11?dh tkm1rol tkm1roh tkm1c0 tkm1c1 tkm1c? tkm?1?dl tkm?1?dh tkm?rol tkm?roh tkm?c0 tkm?c1 tkm?c? tkm31?dl tkm31?dh tkm3rol tkm3roh tkm3c0 tkm3c1 tkm3c? ifs pas0 pas1 pbs0 pbs1 pcs0 pds1 pes0 pes1 fc? tkm41?dl tkm41?dh tkm4rol tkm4roh tkm4c0 tkm4c1 tkm4c? pcs1 pds0 pbp pf pfc pfpu tkm?1?dl tkm?1?dh tkm?rol tkm?roh tkm?c0 tkm?c1 tkm?c? tkm?1?dl tkm?1?dh tkm?rol tkm?roh tkm?c0 tkm?c1 tkm?c? pfs0 special purpose data memory structure C BS66F360
rev. 1.40 ? 0 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?1 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver 00h iar0 01h mp0 0?h iar1 03h mp1l 04h 0?h acc 0?h pcl 07h tblp 08h tblh 09h tbhp 0ah status 0bh 0ch lvdc 0dh integ 0eh 0fh 10h intc0 11h 1?h 19h papu 18h pawu 1bh 1ah 1dh 1ch 1fh pa pac 13h 14h mfi0 1?h mfi1 1?h 17h : unused? ?ead as 00h mfi? wdtc tb0c ctm0c0 ctm0c1 ctm0dl ctm0dh ctm0al ctm0ah ?0h ?1h ??h ?9h ?8h ?bh ?ah ?dh ?ch ?fh ?eh ?3h ?4h ??h ??h ?7h eea 40h 41h 4?h 43h 44h 4?h 4?h 47h 48h 49h 4ah 4bh 4ch 4dh 4eh 4fh ?0h ?1h ??h ?3h ?4h mfi3 lvrc eed 1eh eec se?to? 0 se?to? 0 se?to? 1 ??h ??h ?0h ?1h ??h ?3h ?4h ??h ??h ?7h ?8h ?9h ?ah ?bh ?ch ?dh ?eh ?fh 70h 30h 31h 3?h 38h 3ch 33h 34h 3?h 3?h 37h 3bh 39h 3ah 71h 7?h 73h 74h 7?h 7?h 7bh pbc pbpu pb 3dh 3fh 3eh mp1h iar? mp?l mp?h pscr0 tb1c scc hxtc lxtc rstc pcc pcpu pc ?7h ?8h ?9h ?ah ?bh ?ch ?dh ?eh ?fh simtoc simc0 simc1 simd sima/simc? fc0 fc1 farl farh fd0l fd0h fd1l fd1h fd?l fd?h fd3l fd3h se?to? 1 hircc rstfc intc1 intc? pd pdc pdpu adrl adcr0 adrh adcr1 pscr1 sledc ptmc0 ptmc1 ptmdl ptmdh ptmal ptmah ptmrpl ptmrph stmc0 stmc1 stmdl stmdh stmal stmah stmrp ctm1c0 ctm1c1 ctm1dl ctm1dh ctm1al ctm1ah tsc0 tsc1 tsc? tsc3 pe pec pepu 77h 78h usr ucr1 ucr? txr_rxr brg 79h 7ah tktmr tkc0 tk1?dl tk1?dh tkc1 tkm01?dl tkm01?dh tkm0rol tkm0roh tkm0c0 tkm0c1 tkm0c? tkm11?dl tkm11?dh tkm1rol tkm1roh tkm1c0 tkm1c1 tkm1c? tkm?1?dl tkm?1?dh tkm?rol tkm?roh tkm?c0 tkm?c1 tkm?c? tkm31?dl tkm31?dh tkm3rol tkm3roh tkm3c0 tkm3c1 tkm3c? ifs pas0 pas1 pbs0 pbs1 pcs0 pds1 pes0 pes1 fc? tkm41?dl tkm41?dh tkm4rol tkm4roh tkm4c0 tkm4c1 tkm4c? pcs1 pds0 pbp pf pfc pfpu tkm?1?dl tkm?1?dh tkm?rol tkm?roh tkm?c0 tkm?c1 tkm?c? tkm?1?dl tkm?1?dh tkm?rol tkm?roh tkm?c0 tkm?c1 tkm?c? pfs0 sledc1 pg pgc pgpu 7ch 7dh 7fh 7eh tkm71?dl tkm71?dh tkm7rol tkm7roh tkm7c0 tkm7c1 tkm7c? pgs0 pgs1 phpu ph phc tkm81?dl tkm81?dh tkm8rol tkm8roh tkm8c0 tkm8c1 tkm8c? special purpose data memory structure C bs66f370
rev. 1.40 ?0 de?e??e? 1?? ?01? rev. 1.40 ? 1 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver special function register description most of the special function register details will be described in the relevant functional section. however, several registers require a separate description in this section. indirect addressing registers C iar0, iar1, iar2 the indirect addressing registers, iar0, iar1 and iar2, although having their locations in normal ram register space, do not actually physically exist as normal registers. the method of indirect addressing for ram data manipulation uses these indirect addressing registers and memory pointers, in contrast to direct memory addressing, where the actual memory address is specifed. actions on the iar0, iar1 and iar2 registers will result in no actual read or write operation to these registers but ra ther t o t he m emory l ocation spe cifed by t heir c orresponding me mory poi nters, mp0, mp1l / mp1h or mp2l /mp2h. ac ting a s a pa ir, iar0 a nd mp0 c an t ogether a ccess da ta onl y from se ctor 0 while the iar1 register together with mp1l/mp1h register pair and iar2 register together with mp2l/mp2h register pair can access data from any data memory sector . as the indirect addressing registers are not physically implemented, reading the indirect addressing registers indirectly will return a result of "00h" and writing to the registers indirectly will result in no operation. memory pointers C mp0, mp1h/mp1l, mp2h/mp2l five memory pointers, known as mp0, mp1l, mp1h, mp2l and mp2h, are provided. these memory pointers are phys ically implemented in the d ata m emory and can be manipulated in the same wa y a s n ormal r egisters p roviding a c onvenient wa y wi th wh ich t o a ddress a nd t rack d ata. when any operati on to the relevant indirect addressing registers is carried out, the actual address that the microcontroller is directed to is the address specifed by the related memory pointer . mp0, together with indirect addressing register , iar0, are used to access data from sector 0, while mp1l/mp1h together with iar1 and mp2l/mp2h together with iar2 are used to access data from all data sectors according to the corresponding mp1h or mp2h register. direct addressing can be used in all data sectors using the corresponding instruction which can address all available data memory space. indirect addressing program example ? example 1 data .section data adres1 db ? adres2 db ? adres3 db ? adres4 db ? block db ? code .section at 0 code org 00h start: mov a,04h ; setup size of block mov block,a mov a,offset adres1 ; accumulator loaded with frst ram address mov mp0,a ; setup memory pointer with frst ram address loop: clr iar0 ; clear the data at address defned by mp0 inc mp0 ; increment memory pointer sdz block ; check if last memory location has been cleared jmp loop continue: :
rev. 1.40 ?? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?3 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? example 2 data .section data adres1 db ? adres2 db ? adres3 db ? adres4 db ? block db ? code .section at 0 code org 00h start: mov a,04h ; setup size of block mov block,a mov a,01h ; setup the memory sector mov mp1h,a mov a,offset adres1 ; accumulator loaded with frst ram address mov mp1l,a ; setup memory pointer with frst ram address loop: clr iar1 ; clear the data at address defned by mp1 inc mp1l ; increment memory pointer mp1l sdz block ; check if last memory location has been cleared jmp loop continue: : the important point to note here is that in the example shown above, no reference is made to specifc ram addresses. direct addressing program example using extended instructions data .section data temp db ? code .section at 0 code org 00h start: lmov a ,[m] ; move [m] data to acc lsub a , [m+1] ; compare [m] and [m+1] data snz c ; [m]>[m+1]? jmp continue ; no lmov a ,[m] ; yes, exchange [m] and [m+1] data mov temp,a lmov a,[m+1] lmov [m],a mov a,temp lmov [m+1],a continue: : note: here "m" is a data memory address located in any data memory sectors. for example, m=1f0h, it indicates address 0f0h in sector 1.
rev. 1.40 ?? de?e??e? 1?? ?01? rev. 1.40 ? 3 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver program memory bank pointer C pbp for the bs 66f360 and bs 66f370 device the p rogram m emory is divided into s everal banks . selecting the required program memory area is achieved using the program memory bank pointer , pbp. t he pbp re gister should be prope rly c onfigured be fore t he de vice e xecutes t he "bra nch" operation using the "jmp" or "call" instruction. after that a jump to a non-consecutive program memory address which is located in a certain bank selected by the program memory bank pointer bits will occur. pbp register C BS66F360 bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 pbp0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~1 d7~d1 : general data bits and can be read or written. bit 0 pbp0 : program memory bank point bit 0 0: bank 0 1: bank 1 pbp register C bs66f370 bit 7 6 5 4 3 2 1 0 na ? e d ? d ? d4 d3 d ? d1 pbp1 pbp0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~2 d6~d1 : general data bits and can be read or written. bit 1~0 pbp1~pbp0 : program memory bank point bit1~bit 0 00: bank 0 01: bank 1 10: bank 2 11: bank 3 accumulator C acc the a ccumulator is central to the operation of any microcontroller and is clos ely related w ith operations carried out by the alu. the accumulator is the place where all intermediate results from the alu are stored. w ithout the accumulator it would be necessary to write the result of each c alculation or l ogical ope ration suc h a s a ddition, subt raction, shi ft, e tc., t o t he da ta me mory resulting i n highe r program ming and t iming overheads. da ta t ransfer operat ions usual ly i nvolve the t emporary st orage func tion of t he ac cumulator; for e xample, wh en t ransferring da ta be tween one user defi ned regi ster and anot her, it is necessary to do this by passing the data through the accumulator as no direct transfer between two registers is permitted. program counter low register C pcl to provide additional program control functions, the low byte of the program counter is made accessible to programmers by locating it within the special purpose area of the data memory . by manipulating this register , direct jumps to other program locations are easily implemented. loading a value directly into this pcl register will cause a jump to the specifed program memory location, however, as the register is only 8-bit wide, only jumps within the current program memory page are permitted. when such operations are used, note that a dummy cycle will be inserted.
rev. 1.40 ? 4 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver look-up table registers C tblp, tbhp, tblh these three special function registers are used to cont rol operation of the look-up table which is stored i n t he progra m me mory. t blp a nd t bhp a re t he t able poi nter a nd i ndicates t he l ocation where the table data is located. their value must be setup before any table read commands are executed. their value can be changed, for example using the "inc" or "dec" instructions, allowing for easy table data pointing and reading. tblh is the location where the high order byte of the table data is stored afte r a table read data instruction has been executed. note that the lower order table data byte is transferred to a user defned location. status register C status this 8-bit register contains the zero fag (z), carry fag (c), auxiliary carry fag (ac), overfow fag (ov), sc fag, cz fag, power down fag (pdf), and watchdog time-out fag (t o). these arithmetic/ logical o peration a nd sy stem m anagement fa gs a re u sed t o r ecord t he st atus a nd o peration o f t he microcontroller. with the exceptio n of the t o and pdf fags, bits in the status register can be altered by instructions like most other registers. any data written into the status register will not change the t o or pdf fag. in addition, operations related to the status register may give dif ferent results due to the dif ferent instruction operati ons. the t o fag can be af fected only by a system power -up, a wdt time-out or by executing the "clr wdt" or "hal t" instruction. the pdf fag is af fected only by executing the "halt" or "clr wdt" instruction or during a system power-up. the z, ov, ac, c, sc and cz fags generally refect the status of the latest operations. ? c is set if an operation results in a carry during an addition operation or if a borrow does not take place during a subtraction operation; otherwise c is cleared. c is also af fected by a rotate through carry instruction. ? ac is set if an operation results in a carry out of the low nibbles in addition, or no borrow from the high nibble into the low nibble in subtraction; otherwise ac is cleared. ? z is set if the result of an arithmetic or logical operation is zero; otherwise z is cleared. ? ov is set if an operation results in a carry into the highest-order bit but not a carry out of the highest-order bit, or vice versa; otherwise ov is cleared. ? pdf is cleared by a system power -up or executing the "clr wdt" instruction. pdf is set by executing the "halt" instruction. ? to is cle ared by a system power -up or executing the "clr wdt" or "hal t" instruction. t o is set by a wdt time-out. ? sc is the result of the "xor" operation which is performed by the ov fag and the msb of the current instruction operation result. ? cz is the operational result of dif ferent fags for dif ferent instuctions. refer to register defnitions for more details. in additio n, on entering an interrup t sequence or executing a subroutine call, the status register will not be pushed onto the stack automatically . if the contents of the status registers are important and if the subroutine can corrupt the status register, precautions must be taken to correctly save it.
rev. 1.40 ?4 de?e??e? 1?? ?01? rev. 1.40 ?? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver status register bit 7 6 5 4 3 2 1 0 na ? e sc cz to pdf ov z ac c r/w r r r r r/w r/w r/w r/w por x x 0 0 x x x x "x": unknown bit 7 sc : the result of the "xor" operation which is performed by the ov fag and the msb of the instruction operation result. bit 6 cz : the the operational result of different fags for different instuctions. for sub/subm/lsub/lsubm instructions, the cz fag is equal to the z fag. for sbc/ sbcm/ lsbc/ lsbcm ins tructions, the cz fag is the " and" operation result which is performed by the previous operation cz fag and current operation zero fag. for other instructions, the cz fag willl not be affected. bit 5 to : w atchdog t ime-out fag 0: after power up ow executing the "clr wdt" or "halt" instruction 1: a watchdog time-out occurred bit 4 pdf : power down fag 0: after power up ow executing the "clr wdt" instruction 1: by executing the "halt" instructin bit 3 ov : overfow fag 0: no overfow 1: an operation results in a carry into the highest-order bit but not a carry out of the highest-order bit or vice versa bit 2 z : zero fag 0: the result of an arithmetic or logical operation is not zero 1: the result of an arithmetic or logical operation is zero bit 1 ac : auxiliary fag 0: no auxiliary carry 1: an operation results in a carry out of the low nibbles, in addition, or no borrow from the high nibble into the low nibble in substraction bit 0 c : carry fag 0: no carry-out 1: an operation results in a carry during an addition operation or if a borrow does not take place during a subtraction operation the "c" fag is also affected by a rotate through carry instruction.
rev. 1.40 ?? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?7 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver eeprom data memory these d evices c ontain a n a rea o f i nternal e eprom da ta me mory. e eprom, wh ich st ands f or electrically e rasable progra mmable re ad onl y me mory, i s by i ts na ture a non-vol atile form of re-programmable memory , with data retention even when its power supply is removed. by incorporating this kind of data memory , a w hole new hos t of application pos sibilities are made available to the designer . the avail ability of eeprom storage allows information such as product identification numbers, calibration values, specific user data, system setup data or other product information to be stored directly within the product microcontroller . the process of reading and writing data to the eeprom memory has been reduced to a very trivial affair. device capacity address bs ?? f340 1 ? 8 x 8 00h ~ 7fh bs ?? f3 ? 0 bs ?? f3 ? 0 bs ?? f370 eeprom data memory structure the eep rom data memory capacity is 1288 bits for the series of devices . unlike the program memory and ram data memory , the eeprom data memory is not directly mapped into memory space and is there fore not directly addressable in the same way as the other types of memory . read and w rite operatio ns to the eeprom are carried out in single byte operations using an address and data register in sector 0 and a single control register in sector 1. eeprom registers three registers control the overall operation of the internal eeprom data memory . these are the address register , eea, the data register , eed and a single control register , eec. as both the eea and eed registers are located in sector 0, they can be directly accessed in the same was as any other special function register . the eec register , however , being located in sector 1, can be read from or written to indirectly using the mp1h/mp1l or mp2h/mp2l memory pointer pair and indirect addressing register , iar1 or iar2. because the eec control register is located at address 40h in se ctor 1, t he me mory poi nter l ow byt e re gister, mp1l or mp2l , m ust frst be se t t o t he va lue 40h and the memory pointer high byte register , mp1h or mp2h, set to the value, 01h, before any operations on the eec register are executed. register name bit 7 6 5 4 3 2 1 0 eea eea ? eea ? eea4 eea3 eea ? eea1 eea0 eed d7 d ? d ? d4 d3 d ? d1 d0 eec wren wr rden rd eeprom registers list eea register bit 7 6 5 4 3 2 1 0 na ? e eea ? eea ? eea4 eea3 eea ? eea1 eea0 r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 bit 7 unimplemented, read as 0. bit 6~0 eea6~eea0 : data eeprom address bit 6 ~ bit0
rev. 1.40 ?? de?e??e? 1?? ?01? rev. 1.40 ? 7 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver eed register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 d7~d0 : data eeprom data bit 7~bit0 eec register bit 7 6 5 4 3 2 1 0 na ? e wren wr rden rd r/w r/w r/w r/w r/w por 0 0 0 0 bit 7~4 unimplemented, read as 0. bit 3 wren : data eeprom write enable 0: disable 1: enable this is the d ata eep rom w rite enable bit w hich mus t be s et high before d ata eeprom write operations are carried out. clearing this bit to zero will inhibit data eeprom write operations. bit 2 wr : eeprom write control 0: w rite cycle has fnished 1: activate a write cycle this i s t he da ta e eprom w rite c ontrol b it a nd wh en se t h igh b y t he a pplication program will activ ate a write cycle. this bit will be automatically reset to zero by the hardware after the write cycle has fnished. setting this bit high will have no ef fect if the wren has not frst been set high. bit 1 rden : data eeprom read enable 0: disable 1: enable this is the data eeprom read enable bit which must be set high before data eeprom read operations are carried out. clearing this bit to zero w ill inhibit d ata eeprom read operations. bit 0 rd : eeprom read control 0: read cycle has fnished 1: activate a read cycle this is the data eeprom read control bit and when set high by the applic ation program will activ ate a read cycle. this bit will be automatically reset to zero by the hardware after the read cycle has fnished. setting this bit high will have no ef fect if the rden has not frst been set high. note: the wren, wr, rden and rd can not be set to "1" at the same time in one instruction. the wr and rd can not be set to "1" at the same time. reading data from the eeprom to read data from the eep rom, the read enable bit, rden , in the eec register must frs t be set high to enable the read function. the eeprom address of the data to be read must then be placed in the eea register . if the rd bit in the eec register is now set high, a read cycle will be initiated. setting the rd bit high will not initiate a read operation if the rden bit has not been set. when the read cycle term inates, the rd bit will be automatically cleared to zero, after which the data can be read from the eed register . the data will remain in the eed register until another read or write operation i s e xecuted. t he a pplication pr ogram c an po ll t he r d bi t t o de termine whe n t he da ta i s valid for reading.
rev. 1.40 ? 8 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?9 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver writing data to the eeprom to write data to the eeprom, the eeprom address of the data to be written must frst be placed in t he ee a regist er and t he dat a pla ced in t he ee d regist er. then t he writ e enabl e bit , wren, in the eec register must first be set high to enable the write function. after this, the wr bit in the e ec r egister m ust be i mmediately se t hi gh t o i nitiate a wri te c ycle. t hese t wo i nstructions must be executed consecutively . the global interrupt bit emi should also first be cleared before implementing any write operations, and then set again after the write cycle has started. note that setting the wr bit high will not initiate a write cycle if the wren bit has not been set. as the eeprom write cycle is controlled using an internal timer whose operation is asynchronous to microcontroller system clock, a certain time will elapse before the data will have been written into the eeprom. detecting when the write cycle has fnished can be implemented either by polling the wr bit in the eec register or by using the eeprom interrupt. when the write cycle terminates, the wr bit will be automatically cleared to zero by the microcontroller , informing the user that the data has been written to the eeprom. the application program can therefore poll the wr bit to determine when the write cycle has ended. write protection protection against inadvertent write operation is provided in several ways. after the device is powered on, the w rite enable bit in the control regis ter w ill be cleared preventing any w rite operations. also at power -on the memory pointer high byte register , mp1h or mp2h, will be reset to zero, which means that data memory sector 0 will be selected. as the eeprom control register is located in sector 1, this adds a further measure of protection against spurious write operations. during normal program operati on, ensuring that the w rite enable bit in the cont rol re gister is cleared will safeguard against incorrect write operations. eeprom interrupt the eeprom write interrupt is generated when an eeprom write cycle has ended. the eeprom interrupt must frst be enabled by setting the dee bit in the relevant interrupt register . however , as the eeprom is contained within a multi-function interrupt, the associated multi-function interrupt enable bit must als o be set. when an eeprom w rite cycle ends, the d ef reques t flag and its associated multi-function interrupt request fag will both be set. if the global, eeprom and multi- function interrupts are enabled and the stack is not full, a jump to the associated multi-function interrupt vector will take place. when the interrupt is serviced only the multi-function interrupt fag will be automatically reset, the eeprom interrupt fag must be manually reset by the application program. programming considerations care must be taken that data is not inadvertently written to the eeprom. protection can be periodic by ensuring that the w rite enable bit is normally cleared to zero when not writing. also the memory pointer high byte register could be normally cleared to zero as this would inhibit access to sector 1 where the eeprom control registe r exist. although certainly not necessary , consideration might be given in the appli cation program to the checking of the validity of new write data by a simple read back process. when writing data the wr bit must be set high immediately after the wren bit has been set high, to ensure the write cycle executes correctly . the global interrupt bit emi should also be cleare d before a write cycle is executed and then re-enabled after the write cycle starts. note that the devic e should not enter the idle or sleep mode until the eeprom read or write operation is totally complete. otherwise, the eeprom read or write operation will fail.
rev. 1.40 ?8 de?e??e? 1?? ?01? rev. 1.40 ? 9 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver programming example ? reading data from the eeprom C polling method mov a , eeprom_adres ; user defned address mov e ea, a mov a , 040h ; setup memory pointer low byte mp1l mov m p1l, a ; mp1l points to eec register mov a , 01h ; setup memory pointer high byte mp1h mov m p1h, a set i ar1.1 ; set rden bit, enable read operations set iar1.0 ; start read cycle - set rd bit back: sz iar1.0 ; check for read cycle end jmp b ack clr i ar1 ; disable eeprom write clr m p1h mov a , eed ; move read data to register mov r ead_data, a ? writing data to the eeprom C polling method mov a , eeprom_adres ; user defned address mov e ea, a mov a , eeprom_data ; user defned data mov e ed, a mov a , 040h ; setup memory pointer low byte mp1l mov m p1l, a ; mp1l points to eec register mov a , 01h ; setup memory pointer high byte mp1h mov m p1h, a clr e mi set i ar1.3 ; set wren bit, enable write operations set iar1.2 ; start write cycle - set wr bit set e mi back: sz iar1.2 ; check for write cycle end jmp b ack clr i ar1 ; disable eeprom write clr m p1h
rev. 1.40 70 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 71 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver oscillators various oscillator types offer the user a wide range of functions according to their various application requirements. the fexible features of the oscillator functions ensure that the best optimisation can be achieved in terms of speed and power saving. oscillator selections and operation are selected through a combination of application program and relevant control registers. oscillator overview in additio n to being the source of the main system clock the oscillators also provide clock sources for t he w atchdog t imer a nd t ime b ase i nterrupts. e xternal o scillators r equiring so me e xternal components as well as fully integrated internal oscillators, requiring no external components, are provided t o fo rm a wi de ra nge of bo th fa st a nd sl ow syst em osc illators. al l osc illator op tions a re selected through register programming. the higher frequency oscillators provide higher performance but carry with it the disadvantage of higher power requirements, while the opposite is of course true for the lower frequency oscillators. w ith the capability of dynamically switching between fast and slow system clock, the device has the fexibility to optimize the performance/power ratio, a feature especially important in power sensitive portable applications. type name frequency pins exte ? nal high speed c ? ystal hxt 400 khz~ ? 0 mhz osc1/osc ? inte ? nal high speed rc hirc 8/1 ? /1 ? mhz exte ? nal low speed c ? ystal lxt 3 ? .7 ? 8 khz xt1/xt ? inte ? nal low speed rc lirc 3 ? khz oscillator types system clock confgurations there are four methods of generating the system clock, two high speed oscillators for all devices and two low speed oscillators. the high speed oscillator is the external crystal/ceramic oscillator , hxt , and the internal 8/12/16 mhz rc oscillator , hirc. the two low speed oscillators are the internal 32 khz rc oscillator , lirc, and the external 32.768 khz crystal oscillator , lxt . selecting whether the low or high speed oscillator is used as the system oscillator is implemented using the cks2~cks0 bits in the scc register and as the system clock can be dynamically selected. the actual source clock us ed for the low speed os cillators is chosen via the fss bit in the scc register while for the high speed oscillator the source clock is selected by the fhs bit in the scc register. t he fre quency of t he sl ow spe ed or hi gh spe ed syst em c lock i s de termined usi ng t he cks2~cks0 bits in the scc register . note that two oscillator selectio ns must be made namely one high speed and one low speed system oscillators. it is not possible to choose a no-oscillator selection for either the high or low speed oscillator.
rev. 1.40 70 de?e??e? 1?? ?01? rev. 1.40 71 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver hxt p?es?ale? f h lxt high speed os?illato?s low speed os?illato?s f h /? f h / 1? f h / ?4 f h /8 f h /4 f h / 3? cks ?~ cks 0 f sys f sub f sub hxten fss lirc lxten f lirc f lirc hirc hircen f h fhs system clock confgurations external crystal/ceramic oscillator C hxt the e xternal c rystal/ceramic sy stem osc illator i s t he h igh f requency o scillator, wh ich i s t he default oscillator clock source after power on. for most crystal oscillator confgurations, the simple connection of a crystal across osc1 and osc2 will create the necessary phase shift and feedback for oscillation, without requiring extern al capacitors. however , for some crystal types and frequencies, to ensure oscillation, it may be necessary to add two small value capacitors, c1 and c2. using a ceramic resonator will usually require two small value capacitors, c1 and c2, to be connected as shown for oscillation to occur . the values of c1 and c2 should be selected in consultation with the crystal or resonator manufacturers specifcation. for oscillator stability and to minimise the ef fects of noise and crosstalk, it is important to ensure that the crystal and any associated resistors and capacitors along with interconnecting lines are all located as close to the mcu as possible.                            
                                    ?     ?                ? ?  crystal/resonator oscillator hxt oscillator c1 and c2 values crystal frequency c1 c2 1 ? mhz 0 pf 0 pf 8mhz 0 pf 0 pf 4mhz 0 pf 0 pf 1mhz 100 pf 100 pf note : c1 and c ? values a ? e fo ? guidan ? e only. crystal recommended capacitor values
rev. 1.40 7 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 73 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver internal high speed rc oscillator C hirc the internal rc oscillator is a fully integrated system oscillator requiring no external components. the internal rc oscillator has a fixed frequency of 8/12/16 mhz. device trimming during the manufacturing process and the inclusion of internal frequency compensati on circuits are used to ensure that the infuence of the power supply voltage, temperature and process variations on the oscillation frequency are minimised . as a result, at a power supply of 3v or 5v and at a temperature of 25c degrees, the fxed oscillation frequency of 12mhz will have a tolerance within 2%. note that if this interna l system clock option is selected, as it requires no external pins for its operation, i/ o pins are free for use as normal i/o pins. external 32.768 khz crystal oscillator C lxt the exte rnal 32.768 khz crystal system oscillator is one of the low frequency oscillator choices, which is selected via a software control bit, fss. this clock source has a fxed frequency of 32.768 khz and requires a 32.768 kh z crys tal to be connected betw een pins x t1 and x t2. the external resistor and capacitor components connected to the 32.768 khz crystal are necessary to provide oscillation. for a pplications whe re pre cise fre quencies a re e ssential, t hese c omponents m ay be required to provide frequency compensation due to dif ferent crystal manufacturing tolerances. after the lxt oscillator is enabled by setting the lxten bit to 1, there is a time delay associated with the lxt oscillator waiting for it to start-up. when the microcontroller enters the sleep or idle mode, the system clock is switched of f to stop microcontroller activity and to conserve power . however , in many microcontroller applications it may be necessary to keep the internal timers operational even when the microcontroller is in the sleep or idle mode. t o do this, another clock, independent of the system clock, must be provided. however, for some crystals, to ensure oscillation and accurate frequency generation, it is necessary to add two small value external capacitors, c1 and c2. the exact values of c1 and c2 should be selected in consultation with the crystal or resonator manufacturer s specification. the external parallel feedback resistor, rp, is required. the pin-shared software control bits determine if the xt1/xt2 pins are used for the lxt oscillator or as i/o or other pin-shared functional pins. ? if the lxt oscillator is not used for any clock source, the xt1/xt2 pins can be used as normal i/o or other pin-shared functional pins. ? if the lxt oscilla tor is used for any clock source, the 32.768 khz crystal should be connected to the xt1/xt2 pins. for oscillator stability and to minimise the ef fects of noise and crosstalk, it is important to ensure that the crystal and any associated resistors and capacitors along with interconnecting lines are all located as close to the mcu as possible.                            
                               ?      ?    ? ? ? ?- ? ?  ?  external lxt oscillator
rev. 1.40 7? de?e??e? 1?? ?01? rev. 1.40 73 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver lxt oscillator low power function the l xt osc illator ca n funct ion i n one of t wo mode s, t he spe ed-up mode and t he l ow-power mode. the mode selection is executed using the lxtsp bit in the lxtc register. lxtsp lxt operating mode 0 low-powe ? 1 speed-up when the lxtsp bit is set to high, the lxt quick start mode will be enabled. in the speed-u p mode the lxt oscillator will power up and stabilise quickly . however , after the lxt oscillator has fully powered up, it can be placed into the low-power mode by clearin g the lxtsp bit to zero and the oscill ator will continue to run but with reduced current consumption. it is important to note that the lxt operating mode switching must be properly controlled before the lxt oscillator clock is selected as the system clock source. once the lxt oscillator clock is selected as the system clock source using the cks bit feld and fss bit in the scc register , the lxt oscillator operating mode can not be changed. it should be note that no matter what condition the lxtsp is set to the lxt oscillator will always function normally . the only dif ference is that it will take more time to start up if in the low power mode. internal 32khz oscillator C lirc the internal 32 khz system oscillator is one of the low frequency oscillator choices, which is selected via a software control bit, fss. it is a fully integrated rc oscillator with a typical frequency of 32 khz at 5v , requiring no external components for its implementation. device trimming during the manufacturing process and the inclusion of internal frequency compensation circuits are used to ensure that the infuence of the power supply voltage, temperature and process variations on the oscillation frequency are minimised. as a result, at a power supply of 5v and at a temperature of 25?c degrees, the fxed oscillation frequency of 32 khz will have a tolerance within 10%.
rev. 1.40 74 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 7? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver operating modes and system clocks present day appl ications require that their mi crocontrollers have high performance but often sti ll demand that they consume as little power as possible, conficting requirements that are especially true i n ba ttery powe red port able a pplications. t he fa st c locks re quired for hi gh pe rformance wi ll by t heir na ture i ncrease c urrent c onsumption a nd of c ourse vi ce-versa, l ower spe ed c locks re duce current consumption. as holtek has provided thes e devices with both high and low speed clock sources and the means to switch between them dynamically , the user can optimise the operation of their microcontroller to achieve the best performance/power ratio. system clocks each device has dif ferent clock sources for both the cpu and peripheral function operation. by providing the user with a wide range of clock selections using register programming, a clock system can be confgured to obtain maximum application performance. the main system clock, can come from either a high frequency , f h , or low frequency , f sub , source, and is selected using the cks2~cks0 bits in the scc register . the high speed system clock is sourced from an hxt or hirc oscillator , selected via confguring the fhs bit in the scc register . the low speed system clock source can be sourced from the internal clock f sub . if f sub is selected then it can be sourced by either the lxt or lirc oscillators, selected via confguring the fss bit in the scc register . the other choice, which is a divided version of the high speed system oscillator has a range of f h /2~f h /64.
rev. 1.40 74 de?e??e? 1?? ?01? rev. 1.40 7 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver hxt p?es?ale? f h lxt high speed os?illato?s low speed os?illato?s f h /? f h / 1? f h / ?4 f h /8 f h /4 f h / 3? cks ?~ cks 0 f sys f sub f sub hxten fss lirc lxten f lirc f lirc hirc hircen f h lvr wdt f lirc f sys /4 f psc0 ti?e base 0 clksel 0[1:0] f sub f sys p?es?ale? 0 tb 0[?:0] f sys /4 clksel 1[1:0] f sub f sys fhs f psc1 ti?e base 1 p?es?ale? 1 tb 1[?:0] device clock confgurations note: when the system clock source f sys is switched to f sub from f h , the high speed oscillation can be stopped to conserve the power or continue to oscillate to provide the clock source, f h ~f h /64, for peripheral circuit to use, which is determined by confguring the corresponding high speed oscillator enable control bit.
rev. 1.40 7 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 77 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver system operation modes there are six dif ferent modes of operation for the microcontroller , each one with its ow n special characteristics and which can be chosen according to the specific performance and power requirements of the appl ication. there are two modes all owing normal operati on of the microcontroller, the normal mode and slow mode. the remaining four modes, the sleep , idle0, idle1 and idl e2 mode are used when the microcontroller cpu i s switched off t o conserve power. operation mode cpu register setting f sys f h f sub f lirc fhiden fsiden cks2~cks0 normal on x x 000~110 f h ~f h / ? 4 on on on slow on x x 111 f sub on/off (1) on on idle0 off 0 1 000~110 off off on on 111 on idle1 off 1 1 xxx on on on on idle ? off 1 0 000~110 on on off on 111 off sleep off 0 0 xxx off off off on ( ? ) note: 1. the f h clock will be switched on or of f by confguring the corresponding oscillator enable bit in the slow mode. 2. the f lirc clock will be switched on since the wdt function is always enabled. normal mode as the name suggests this is one of the main operating modes where the microcontroller has all of its functions operational and where the system clock is provided by one of the high speed oscillators. this mode operate s allowing the microcontroller to operate normally with a clock source will come from one of the high speed oscillators, either the hxt or hirc oscillators. the high speed oscillator will however first be divided by a ratio ranging from 1 to 64, the actual ratio being selected by the cks2~cks0 bits in the scc register .although a high speed oscillator is used, running the microcontroller at a divided clock ratio reduces the operating current. slow mode this is also a mode where the microcontroller operates normally altho ugh now with a slower speed clock source. the clock source used will be from f sub . the f sub clock is derived from either the lirc or lxt oscillator. sleep mode the sleep mode is entered when an hal t instruction is executed and when the fhiden and fsiden bit are low . in the sleep mode the cpu will be stopped . however the f lirc clock still continues to operate since the wdt function is always enabled. idle0 mode the idle0 mode is entered when an hal t instruction is executed and when the fhiden bit in the s cc regis ter is low and the f siden bit in the s cc regis ter is high. in the id le0 m ode the cpu wi ll be swi tched of f but t he l ow spe ed osc illator wi ll be t urned on t o dri ve som e pe ripheral functions.
rev. 1.40 7? de?e??e? 1?? ?01? rev. 1.40 77 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver idle1 mode the idle1 mode is entered when an hal t instruction is executed and when the fhiden bit in the scc register is high and the fsiden bit in the scc register is high. in the idle1 mode the cpu will be switched of f but both the high and low speed oscillators will be turned on to provide a clock source to keep some peripheral functions operational. idle2 mode the idle2 mode is entered when an hal t instruction is executed and when the fhiden bit in the scc register is high and the fsiden bit in the scc register is low . in the idle2 mode the cpu will be switched of f but the high speed oscillator will be turned on to provide a clock source to keep some peripheral functions operational. control registers the registers, scc, hircc, hxtc and lxtc, are used to control the system clock and the corresponding oscillator confgurations. register name bit 7 6 5 4 3 2 1 0 scc cks ? cks1 cks0 fhs fss fhiden fsiden hircc hirc1 hirc0 hircf hircen hxtc hxtm hxtf hxten lxtc lxtsp lxtf lxten system operating mode control registers list scc register bit 7 6 5 4 3 2 1 0 na ? e cks ? cks1 cks0 fhs fss fhiden fsiden r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 bit 7~5 cks2~cks0 : system clock selection 000: f h 001: f h /2 010: f h /4 011: f h /8 100: f h /16 101: f h /32 110: f h /64 111: f sub these three bits are used to select which clock is used as the system clock source. in addition to the system clock source directly derived from f h or f sub , a divided version of the high speed system oscillator can also be chosen as the system clock source. bit 4 unimplemented, read as 0. bit 3 fhs : high frequency clock selection 0: hirc 1: hxt bit 2 fss : low frequency clock selection 0: lirc 1: lxt
rev. 1.40 78 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 79 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 1 fhiden : high frequency oscillator control when cpu is switched off 0: disable 1: enable this bit is used to control whether the high speed oscillator is activated or stopped when the cpu is switched off by executing an "halt" instruction. bit 0 fsiden : low frequency oscillator control when cpu is switched off 0: disable 1: enable this bi t i s use d t o cont rol whe ther t he l ow spe ed osc illator i s ac tivated or st opped when the cpu is sw itched of f by executing an " halt" instruction. the lirc oscillator is controlled by this bit together with the wdt function enable control when the lirc is selected to be the low speed oscillator clock source or the wdt function is enabled respectively . if this bit is cleared to 0 but the wdt function is enabled, the lirc oscillator will also be enabled. hircc register bit 7 6 5 4 3 2 1 0 na ? e hirc1 hirc0 hircf hircen r/w r/w r/w r/w r/w por 0 0 0 1 bit 7~4 unimplemented, read as 0. bit 3~2 hirc1~hirc0 : hirc frequency selection 00: 8 mhz 01: 12 mhz 10: 16 mhz 11: 8 mhz when the hirc oscillator is enabled or the hirc frequency selection is changed by application program, the clock frequency w ill automatically be changed after the hircf fag is set to 1. bit 1 hircf : hirc oscillator stable fag 0: hirc unstable 1: hirc stable this bit is used to indi cate whe ther the hirc oscilla tor is stable or not. when the hircen bit is set to 1 to enable the hirc oscillator or the hirc frequency selection is c hanged by a pplication progra m, t he hircf bi t wi ll frst be c leared t o 0 a nd t hen set to 1 after the hirc oscillator is stable. bit 0 hircen : hirc oscillator enable control 0: disable 1: enable
rev. 1.40 78 de?e??e? 1?? ?01? rev. 1.40 79 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver hxtc register bit 7 6 5 4 3 2 1 0 na ? e hxtm hxtf hxten r/w r/w r r/w por 0 0 0 bit 7~3 unimplemented, read as 0. bit 2 hxtm : hxt mode selection 0: hxt frequency 10 mhz 1: hxt frequency >10 mhz this bit is used to select the hxt oscillator operating mode. note that this bit must be properly confgured before the hxt is enabled. when the hxten bit is set to 1 to enable the hxt oscillator, it is invalid to change the value of this bit. bit 1 hxtf : hxt oscillator stable fag 0: hxt unstable 1: hxt stable this bit is used to indicate whether the hxt oscillator is stable or not. when the hxten bit is set to 1 to enable the hxt oscillator , the hxtf bit will frst be cleared to 0 and then set to 1 after the hxt oscillator is stable. bit 0 hxten : hxt oscillator enable control 0: disable 1: enable lxtc register bit 7 6 5 4 3 2 1 0 na ? e lxtsp lxtf lxten r/w rw r r/w por 0 0 0 bit 7~3 unimplemented, read as 0. bit 2 lxtsp : lxt oscillator speed-up control 0: disable C low power 1: enable C speed up this bit is used to control whether the lxt oscillator is operating in the low power or quick start mode. when the lxtsp bit is set to 1, the lxt oscillato r will oscillate quickly but consume more power . if the lxtsp bit is cleared to 0, the lxt oscillator will consume less power but take longer time to stablise. it is important to note that this bi t c an not be c hanged a fter t he l xt osc illator i s se lected a s t he syst em c lock source using the cks2~cks0 and fss bits in the scc register. bit 1 lxtf : lxt oscillator stable fag 0: lxt unstable 1: lxt stable this bi t i s use d t o i ndicate whe ther t he l xt osc illator i s st able or not . w hen t he lxten bit is set to 1 to enable the lxt oscillator , the lxtf bit will frst be cleared to 0 and then set to 1 after the lxt oscillator is stable. bit 0 lxten : lxt oscillator enable control 0: disable 1: enable
rev. 1.40 80 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 81 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver operating mode switching these devices can switch between operating modes dynamically allowing the user to select the best performance/power ratio for the pres ent task in hand. in this w ay microcontroller operations that do not require high performance can be executed using slower clocks thus requiring less operating current and prolonging battery life in portable applications. in simple terms, mode switching between the normal mode and slow mode is executed using the cks2~cks0 bits in the scc register while mode switching from the normal/slow modes to t he sl eep/idle mode s i s e xecuted vi a t he hal t i nstruction. w hen a n hal t i nstruction i s executed, whet her t he de vice e nters t he idle mode or t he sle ep mode i s de termined by t he condition of the fhiden and fsiden bits in the scc register. normal f sys =f h ~f h /?4 f h on cpu ?un f sys on f sub on slow f sys =f sub f sub on cpu ?un f sys on f h on/off idle0 halt inst?u?tion exe?uted cpu stop fhiden=0 fsiden=1 f h off f sub on idle1 halt inst?u?tion exe?uted cpu stop fhiden=1 fsiden=1 f h on f sub on idle2 halt inst?u?tion exe?uted cpu stop fhiden=1 fsiden=0 f h on f sub off sleep halt inst?u?tion exe?uted cpu stop fhiden=0 fsiden=0 f h off f sub off
rev. 1.40 80 de?e??e? 1?? ?01? rev. 1.40 81 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver normal mode to slow mode switching when r unning i n t he nor mal mo de, wh ich u ses t he h igh sp eed sy stem o scillator, a nd t herefore consumes m ore powe r, t he syste m c lock c an swit ch t o run i n t he sl ow mode by se t t he cks2~cks0 bits to "1 11" in the scc register . this will then use the low speed system oscillator which wi ll c onsume l ess po wer. use rs m ay de cide t o do t his fo r c ertain op erations whi ch do no t require high performance and can subsequently reduce power consumption. the slow mode is sourced from the lxt or lirc oscillator determined by the fss bit in the scc register and therefore requires this oscillator to be stable before full mode switching occurs. normal mode slow mode cks?~cks0 = 111 sleep mode fhiden=0? fsiden=0 halt inst?u?tion is exe?uted idle0 mode fhiden=0? fsiden=1 halt inst?u?tion is exe?uted idle1 mode fhiden=1? fsiden=1 halt inst?u?tion is exe?uted idle2 mode fhiden=1? fsiden=0 halt inst?u?tion is exe?uted
rev. 1.40 8 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 83 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver slow mode to normal mode switching in slow mode the system clock is derived from f sub . when system clock is switched back to the normal mode from f sub , the cks2~cks0 bits should be set to "000" ~"1 10" and then the system clock will respectively be switched to f h ~ f h /64. however, i f f h i s not use d i n sl ow m ode a nd t hus swi tched of f, i t wi ll t ake som e t ime t o re - oscillate and stabilise when switching to the normal mode from the slow mode. this is monitored using the hxtf bit in the hxtc register or the hircf bit in the hircc register . the time duration required for the high speed system oscillator stabilization is specified in the a.c. characteristics. normal mode slow mode cks?~cks0 = 000~110 sleep mode fhiden=0? fsiden=0 halt inst?u?tion is exe?uted idle0 mode fhiden=0? fsiden=1 halt inst?u?tion is exe?uted idle1 mode fhiden=1? fsiden=1 halt inst?u?tion is exe?uted idle2 mode fhiden=1? fsiden=0 halt inst?u?tion is exe?uted entering the sleep mode there is only one way for the device to enter the sleep mode and that is to execute the "hal t" instruction in the application program with both the fhiden and fsiden bits in the scc register equal to "0". in this mode all the clocks and functions will be switched off except the wdt function. when this instruction is executed under the conditions described above, the following will occur: ? the syst em c lock wi ll be st opped a nd t he a pplication progra m wi ll st op a t t he "hal t" instruction. ? the data memory contents and registers will maintain their present condition. ? the i/o ports will maintain their present conditions. ? in t he st atus r egister, t he po wer do wn fa g pdf wi ll b e se t, a nd w dt t imeout fa g t o wi ll b e cleared. ? the wdt will be cleared and resume counting as the wdt function is always enabled.
rev. 1.40 8? de?e??e? 1?? ?01? rev. 1.40 83 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver entering the idle0 mode there is only one way for the device to enter the idle0 mode and that is to execute the "hal t" instruction in the application program with the fhiden bit in the scc register equal to "0" and the fsiden bit in the scc register equal to "1". when this instruction is executed under the conditions described above, the following will occur: ? the f h clock will be stopped and the applic ation program will stop at the "hal t" instruction, but the f sub clock will be on. ? the data memory contents and registers will maintain their present condition. ? the i/o ports will maintain their present conditions. ? in t he st atus r egister, t he po wer do wn fa g pdf wi ll b e se t, a nd w dt t imeout fa g t o wi ll b e cleared. ? the wdt will be cleared and resume counting as the wdt function is always enabled. entering the idle1 mode there is only one way for the device to enter the idle1 mode and that is to execute the "hal t" instruction in the application program with both the fhiden and fsiden bits in the scc register equal to "1". when this instruction is executed under the conditions described above, the following will occur: ? the f h and f sub clocks will be on but the application program will stop at the "halt" instruction. ? the data memory contents and registers will maintain their present condition. ? the i/o ports will maintain their present conditions. ? in t he st atus r egister, t he po wer do wn fa g pdf wi ll b e se t, a nd w dt t imeout fa g t o wi ll b e cleared. ? the wdt will be cleared and resume counting as the wdt function is always enabled. entering the idle2 mode there is only one way for the device to enter the idle2 mode and that is to execute the "hal t" instruction in the application program with the fhiden bit in the scc register equal to "1" and the fsiden bit in the scc register equal to "0". when this instruction is executed under the conditions described above, the following will occur: ? the f h clock will be on but the f sub clock will be of f and the applicatio n program will stop at the "halt" instruction. ? the data memory contents and registers will maintain their present condition. ? the i/o ports will maintain their present conditions. ? in t he st atus r egister, t he po wer do wn fa g pdf wi ll b e se t, a nd w dt t imeout fa g t o wi ll b e cleared. ? the wdt will be cleared and resume counting as the wdt function is always enabled.
rev. 1.40 84 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 8? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver standby current considerations as the main reason for entering the sleep or idle mode is to keep the current consumption of the device to as low a value as possible, perhaps only in the order of several micro-amps except in the idle1 and idle2 mode, there are other considerations which must also be taken into account by the circuit designer if the power consumption is to be minimised. special attention must be made to t he i/ o pi ns on t he de vice. al l hi gh-impedance i nput pi ns m ust be c onnected t o e ither a fxed high or low level as any foating input pins could create internal oscillations and result in increased current consumpti on. this also applies to devices which have dif ferent package types, as there may be unbonbed pins. these must eit her be set up as out puts or if setup as inputs must have pul l-high resistors connected. care must also be taken with the loads, which are connected to i/o pins, which are setup as outputs. these should be placed in a condition in which minimum current is drawn or connected only to external circuits that do not draw current, such as other cmos inputs. also note that additional standby current will also be required if the lirc oscillator has enabled. in the idle1 and idle 2 mode the high speed oscillator is on, if the peripheral function clock source is derived from the high speed oscillator , the additional standby current will also be perhaps in the order of several hundred micro-amps. wake-up to minimise power consumption the device can enter the sleep or any idle mode, where the cpu will be switched of f. however , when the device is woken up again, it will take a considerable time for the original system oscillator to restart, stablise and allow normal operation to resume. after the system enters the sleep or idle mode, it can be woken up from one of various sources listed as follows: ? an external falling edge on port a ? a system interrupt ? a wdt overfow when the device executes the "hal t" instruction, the pdf fag will be set to 1. the pdf fag will be cleare d to 0 if the device experi ences a system power -up or executes the clear w atchdog t imer instruction. if the system is woken up by a wdt overfow , a w atchdog t imer reset will be initiated and the t o fag will be set to 1. the t o fag is set if a wdt time-out occurs and causes a wake-up that only resets the program counter and stack pointer, other fags remain in their original status. each pin on port a can be setup using the p awu register to permit a negative transition on the pin to wake up the system . when a port a pin wake-up occurs, the program wil l resume executi on at the instruction following the "hal t" instruction. if the system is woken up by an interrupt, then two possible situations may occur . the frst is where the related interrupt is disabled or the interrupt is enabled but the stack is full, in which case the program will resume execution at the instruction following the "hal t" instruction. in this situation, the interrupt which woke up the device will not be immediately serviced, but wukk rather be serviced later when the related interrupt is fnally enabled o r wh en a st ack l evel b ecomes f ree. t he o ther si tuation i s wh ere t he r elated i nterrupt i s enabled and the stack is not full, in which case the regular interrupt response takes place. if an interrupt request fag is set high before entering the sleep or idle mode, the wake-up function of the related interrupt will be disabled.
rev. 1.40 84 de?e??e? 1?? ?01? rev. 1.40 8 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver watchdog timer the w atchdog t imer is provided to prevent program malfunctions or sequences from jumping to unknown locations, due to certain uncontrollable external events such as electrical noise. watchdog timer clock source the w atchdog t imer clock source is provided by the internal rc oscillator , f lirc . the lirc internal oscillator has an approximate frequency of 32 khz and this specifed internal clock period can vary with v dd , tempera ture and process variations . the w atchdog t imer source clock is then subdivided by a ratio of 2 8 to 2 18 to give longer timeouts, the actual value being chosen using the ws2~ws0 bits in the wdtc register. watchdog timer control register a single register , wdtc, controls the required timeout period as well as the enable/disable operation. this register controls the overall operation of the w atchdog t imer. wdtc register bit 7 6 5 4 3 2 1 0 na ? e we4 we3 we ? we1 we0 ws ? ws1 ws0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 1 0 1 0 0 1 1 bit 7~3 we4~we0 : wdt function enable control 10101 or 01010: enabled other values: reset mcu if these bits are changed due to adverse environmental conditions, the microcontroller will be reset. the reset operation will be activated after 2~3 lirc clock cycles and the wrf bit in the rstfc register will be set to 1. bit 2~0 ws2~ws0 : wdt time-out period selection 000: 2 8 /f lirc 001: 2 10 /f lirc 010: 2 12 /f lirc 011: 2 14 /f lirc 100: 2 15 /f lirc 101: 2 16 /f lirc 110: 2 17 /f lirc 111: 2 18 /f lirc these t hree b its d etermine t he d ivision r atio o f t he wa tchdog t imer so urce c lock, which in turn determines the time-out period. rstfc register bit 7 6 5 4 3 2 1 0 na ? e rstf lvrf lrf wrf r/w r/w r/w r/w r/w por 0 x 0 0 "x": unknown bit 7~4 unimplemented, read as "0" bit 3 rstf : reset control register software reset fag described elsewhere.
rev. 1.40 8 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 87 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 2 lvrf : lvr function reset fag described elsewhere. bit 1 lrf : lvr control register software reset fag described elsewhere. bit 0 wrf : wdt control register software reset fag 0: not occurred 1: occurred this b it i s se t t o 1 b y t he w dt c ontrol r egister so ftware r eset a nd c leared b y t he application program. note that this bit can only be cleared to 0 by the application program. watchdog timer operation the w atchdog t imer ope rates by provi ding a de vice re set whe n i ts t imer ove rfows. t his m eans that i n t he a pplication pro gram a nd dur ing nor mal ope ration t he use r ha s t o st rategically c lear t he watchdog t imer before it overfows to prevent the w atchdog t imer from executing a reset. this is done using the clear watchdog instruction. if the program malfunctions for whatever reason, jumps to an unknown location, or enters an endless loop, the clear instructio n will not be executed in the correct manner, in which case the w atchdog t imer will overfow and reset the device. w ith regard to the w atchdog t imer enable/disable function, there are fve bits, we4~we0, in the wdtc register to of fer the enable /disable control and reset control of the w atchdog t imer. the wdt function will be enable d when the we4~we0 bits are set to a value of 01010b or 10101b. if the we4~we0 bits are se t t o a ny o ther v alues o ther t han 0 1010b a nd 1 0101b, i t wi ll r eset t he d evice a fter 2 ~3 f lirc clock cycles. after power on these bits will have a value of 01010b. we4 ~ we0 bits wdt function 10101b o ? 01010b ena ? le any othe ? value reset mcu watchdog timer enable/disable control under normal program operation, a w atchdog t imer time-out will initialise a device reset and set the status bit t o. however, if the system is in the sleep or idle mode, when a w atchdog t imer time-out occurs, the t o bit in the status register will be set and only the program counter and stack pointer will be reset. three methods can be adopted to clear the contents of the w atchdog t imer. the frst is a wdt reset, which means a certain value except 01010b and 10101b written into the we4~we0 feld, the second is using the w atchdog t imer software clear instruction and the third is via a halt instruction. there is only one method of using software instruction to clear the w atchdog t imer. that is to use the single "clr wdt" instruction to clear the wdt contents. the maximum time out period is when the 2 18 division ratio is selected. as an example, with a 32 khz lirc oscillat or as its source clock, this will give a maximum watchdog period of around 8s for the 2 18 division ratio and a minimum timeout of 7.8ms for the 2 8 division ration. ? clr wdt ? inst?u?tion 8- stage divide? wdt p?es?ale? we 4~ we 0 ?its wdtc registe? reset mcu lirc f lirc f lirc /? 8 8- to -1 mux clr ws ?~ ws 0 (f lirc /? 8 ~ f lirc /? 18 ) wdt ti?e -out (? 8 /f lirc ~ ? 18 /f lirc ) ? halt ? inst?u?tion watchdog timer
rev. 1.40 8? de?e??e? 1?? ?01? rev. 1.40 87 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver reset and initialisation a reset function is a fundamental part of any microcontroller ensuring that the device can be set to some predetermined condition irrespective of outside parameters. the most important reset condition is after power is frst applied to the microcontroller . in this case, internal circuitry will ensure that the mi crocontroller, after a short delay , will be in a well defined state and ready to execute t he fr st p rogram i nstruction. af ter t his p ower-on r eset, c ertain i mportant i nternal r egisters will be set to defned states before the program commences. one of these registers is the program counter, which will be reset to zero forcing the microcontroller to begin program execution from the lowest program memory address. in addition to the pow er-on res et, another res et exis ts in the form of a low v oltage res et, l vr, where a ful l re set is im plemented in sit uations whe re the power supply vol tage fa lls below a certain t hreshold. anot her t ype of re set i s whe n t he w atchdog t imer ove rflows a nd re sets t he microcontroller. all types of reset operations result in different register conditions being setup. reset functions there are five w ays in w hich a microcontroller res et can occur , through events occurring both internally and externally. power-on reset the m ost fund amental a nd una voidable re set i s t he one t hat oc curs a fter powe r i s frst a pplied t o the microcontroller . as well as ensuring that the program memory begins execution from the frst memory address, a pow er-on reset also ensures that certain other registers are preset to know n conditions. all the i/o port and port control registers will power up in a high condition ensuring that all pins will be frst set to inputs. v dd powe? - on reset sst ti?e -out t rstd 1rwh w ??7' lv srzhurq ghod zlwk wslfdo wlph pv power-on reset timing chart internal reset control there is an intern al reset control register , rstc, which is used to provide a reset when the device operates abnormal ly due to the environmental noise interference. if the content of the rstc register is set to any value other than 01010101b or 10101010b, it will reset the device after 2~3 f lirc clock cycles. after power on the register will have a value of 01010101b. rstc7 ~ rstc0 bits reset function 01010101b no ope ? ation 10101010b no ope ? ation any othe ? value reset mcu internal reset function control
rev. 1.40 88 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 89 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? rstc register bit 7 6 5 4 3 2 1 0 na ? e rstc7 rstc ? rstc ? rstc4 rstc3 rstc ? rstc1 rstc0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 1 0 1 0 1 0 1 bit 7~0 rstc7~rstc0 : reset function control 01010101: no operation 10101010: no operation other values: reset mcu if these bits are changed due to adverse environmental conditions, the microcontroller will be reset. the reset operation will be activated after 2~3 lirc clock cycles and the rstf bit in the rstfc register will be set to 1. ? rstfc register bit 7 6 5 4 3 2 1 0 na ? e rstf lvrf lrf wrf r/w r/w r/w r/w r/w por 0 x 0 0 "x": unknown bit 7~4 unimplemented, read as "0" bit 3 rstf : reset control register software reset fag 0: not occurred 1: occurred this bit is set to 1 by the rstc control register software reset and cleared by the application pr ogram. not e t hat t his bi t c an on ly be c leared t o 0 by t he a pplication program. bit 2 lvrf : lvr function reset fag described elsewhere. bit 1 lrf : lvr control register software reset fag described elsewhere. bit 0 wrf : wdt control register software reset fag described elsewhere. low voltage reset C lvr the micr ocontroller contains a low voltage reset circuit in order to monitor the supply voltage of the device. the l vr function is always enabled with a specifc l vr voltag e, v lvr . if the supply voltage of the device drops to within a range of 0.9v~v lvr such as might occur when changing the battery , the l vr will automatically reset the device internally and the l vrf bit in the rstfc register will also be set to 1. for a valid l vr signal, a low supply voltage, i.e., a voltage in the range between 0.9v~ v lvr must exist for a tim e greater than that specifed by t lvr in the l vd/lvr characteristics. if the low supply voltage state does not exceed this value, the l vr will ignore the low supply voltage and will not perform a reset function. the actual v lvr value can be selected by the l vs bits in the l vrc register . if the l vs7~lvs0 bits have any other value, which may perhaps occur due to adverse environmental conditions such as noise, the l vr will reset the device after 2~3 f lirc clock cycles. when this happens, the lrf bit in the rstfc register will be set to 1. after power on the register will have the value of 01010101b. note that the l vr function will be automatically disabled when the device enters the power down mode.
rev. 1.40 88 de?e??e? 1?? ?01? rev. 1.40 89 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver                 note: t rstd is power-on delay with typical time=50ms low voltage reset timing chart ? lvrc register bit 7 6 5 4 3 2 1 0 na ? e lvs7 lvs ? lvs ? lvs4 lvs3 lvs ? lvs1 lvs0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 1 0 1 0 1 0 1 bit 7~0 lvs7~lvs0 : lvr voltage select 01010101: 2.1v 00110011: 2.55v 10011001: 3.15v 10101010: 3.8v other values: generates a mcu reset C register is reset to por value when an actual low voltage condit ion occurs, as specifed by one of the four defned lvr voltage value above, an mcu reset will generated. the reset operation will be activated after 2~3 f lirc clock cycles. in this situation the register conte nts will remain the same after such a reset occurs. any re gister va lue, o ther t han t he fo ur d efned re gister v alues a bove, wi ll a lso re sult i n the generation of an mcu reset. t he reset operation wi ll be activated after 2~3 f lirc clock cycles. however in this situation the register contents will be reset to the por value. ? rstfc register bit 7 6 5 4 3 2 1 0 na ? e rstf lvrf lrf wrf r/w r/w r/w r/w r/w por 0 x 0 0 "x": unknown bit 7~4 unimplemented, read as "0" bit 3 rstf : reset control register software reset fag described elsewhere. bit 2 lvrf : lvr function reset fag 0: not occurred 1: occurred this bit is set to 1 when a specifc low voltage reset condition occurs. note that this bit can only be cleared to 0 by the application program. bit 1 lrf : lvr control register software reset fag 0: not occurred 1: occurred this bit is set to 1 by the l vrc control register contains any undefned l vr voltage register values. this in ef fect acts like a software-reset function. note that this bit can only be cleared to 0 by the application program. bit 0 wrf : wdt control register software reset fag described elsewhere.
rev. 1.40 90 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 91 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver watchdog time-out reset during normal operation the w atchdog time-out reset during normal operation is the same as the hardw are low v oltage reset except that the w atchdog time-out fag t o will be set to "1".                    note: t rstd is power-on delay with typical time=16.7ms wdt time-out reset during normal operation timing chart watchdog time-out reset during sleep or idle mode the w atchdog time-out reset during sleep or idle mode is a little dif ferent from other kinds of re set. mo st of t he c onditions re main unc hanged e xcept t hat t he pro gram count er a nd t he st ack pointer will be cleared to "0" and the t o fag will be set to "1". refer to the a.c. characteristics for t sst details.               wdt time-out reset during sleep or idle mode timing chart reset initial conditions the dif ferent types of reset described af fect the reset fags in dif ferent ways. these fags, known as p df and t o are located in the s tatus register and are controlled by various microcontroller operations, su ch a s t he sl eep o r i dle mo de f unction o r w atchdog t imer. t he r eset f lags a re shown in the table: to pdf reset function 0 0 powe ? -on ? eset u u lvr ? eset du ? ing normal o ? slow mode ope ? ation 1 u wdt ti ? e-out ? eset du ? ing normal o ? slow mode ope ? ation 1 1 wdt ti ? e-out ? eset du ? ing idle o ? sleep mode ope ? ation "u" stands fo ? un ? hanged the following table indicates the way in which the various components of the microcontroller are affected after a power-on reset occurs. item reset function p ? og ? a ? counte ? reset to ze ? o inte ?? upts all inte ?? upts will ? e disa ? led wdt ? ti ? e base clea ? afte ? ? eset ? wdt ? egins ? ounting ti ? e ? modules ti ? e ? modules will ? e tu ? ned off input/output po ? ts i/o po ? ts will ? e setup as inputs sta ? k pointe ? sta ? k pointe ? will point to the top of the sta ? k
rev. 1.40 90 de?e??e? 1?? ?01? rev. 1.40 91 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver the dif ferent kinds of resets all af fect the internal registers of the micr ocontroller in dif ferent ways. to ensure reliable continuation of normal program execution after a reset occurs, it is important to know what condition the microcontroller is in after a particular reset occurs. the following table describes how each type of reset affects the microcontroller internal registers. register bs66f340 bs66f350 BS66F360 bs66f370 reset (power on) lvr reset (normal operation) wdt time-out (normal operation) wdt time-out (idle or sleep)* iar0 xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu mp0 0000 0000 0000 0000 0000 0000 uuuu uuuu iar1 xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu mp1l 0000 0000 0000 0000 0000 0000 uuuu uuuu mp1h 0000 0000 0000 0000 0000 0000 uuuu uuuu acc xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu pcl 0000 0000 0000 0000 0000 0000 0000 0000 tblp xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu tblh xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu tbhp ---- xxxx ---- uuuu ---- uuuu ---- uuuu tbhp ---x xxxx ---u uuuu ---u uuuu ---u uuuu tbhp --xx xxxx --uu uuuu --uu uuuu --uu uuuu tbhp -xxx xxxx -uuu uuuu -uuu uuuu -uuu uuuu status xx00 xxxx uuuu uuuu xx1u uuuu uu11 uuuu pbp 0000 0000 0000 0000 0000 0000 uuuu uuuu iar ? xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu mp ? l 0000 0000 0000 0000 0000 0000 uuuu uuuu mp ? h 0000 0000 0000 0000 0000 0000 uuuu uuuu rstfc ---- 0x00 ---- u1uu ---- uuuu ---- uuuu intc0 -000 0000 -000 0000 -000 0000 -uuu uuuu intc1 0000 0000 0000 0000 0000 0000 uuuu uuuu intc ? 0000 0000 0000 0000 0000 0000 uuuu uuuu pa 1111 1111 1111 1111 1111 1111 uuuu uuuu pac 1111 1111 1111 1111 1111 1111 uuuu uuuu papu 0000 0000 0000 0000 0000 0000 uuuu uuuu pawu 0000 0000 0000 0000 0000 0000 uuuu uuuu pb 1111 1111 1111 1111 1111 1111 uuuu uuuu pbc 1111 1111 1111 1111 1111 1111 uuuu uuuu pbpu 0000 0000 0000 0000 0000 0000 uuuu uuuu integ ---- 0000 ---- 0000 ---- 0000 ---- uuuu scc 000- 0000 000- 0000 000- 0000 uuu- uuuu hircc ---- 0001 ---- 0001 ---- 0001 ---- uuuu hxtc ---- -000 ---- -000 ---- -000 ---- -uuu lxtc ---- -000 ---- -000 ---- -000 ---- -uuu lvdc --00 0000 --00 0000 --00 0000 --uu uuuu lvrc 0101 0101 0101 0101 0101 0101 uuuu uuuu wdtc 0101 0011 0101 0011 0101 0011 uuuu uuuu rstc 0101 0101 0101 0101 0101 0101 uuuu uuuu pc ---- 1111 ---- 1111 ---- 1111 ---- uuuu pc 1111 1111 1111 1111 1111 1111 uuuu uuuu pcc ---- 1111 ---- 1111 ---- 1111 ---- uuuu
rev. 1.40 9 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 93 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver register bs66f340 bs66f350 BS66F360 bs66f370 reset (power on) lvr reset (normal operation) wdt time-out (normal operation) wdt time-out (idle or sleep)* pcc 1111 1111 1111 1111 1111 1111 uuuu uuuu pcpu ---- 0000 ---- 0000 ---- 0000 ---- uuuu pcpu 0000 0000 0000 0000 0000 0000 uuuu uuuu pd 1111 1111 1111 1111 1111 1111 uuuu uuuu pdc 1111 1111 1111 1111 1111 1111 uuuu uuuu pdpu 0000 0000 0000 0000 0000 0000 0uuuu uuuu mfi0 --00 --00 --00 --00 --00 --00 --uu --uu mfi1 0000 0000 0000 0000 0000 0000 uuuu uuuu mfi ? -000 -000 -000 -000 -000 -000 -uuu -uuu mfi3 --00 --00 --00 --00 --00 --00 --uu --uu adrl (adrfs=0) xxxx ---- xxxx ---- xxxx ---- uuuu ---- adrl (adrfs=1) xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu adrh (adrfs=0) xxxx xxxx uuuu uuuu uuuu uuuu uuuu uuuu adrh (adrfs=1) ---- xxxx ---- uuuu ---- uuuu ---- uuuu adcr0 0000 0000 0000 0000 0000 0000 uuuu uuuu adcr1 0-00 -000 0-00 -000 0-00 -000 u-uu -uuu pscr0 ---- --00 ---- --00 ---- --00 ---- --uu tb0c 0--- -000 0--- -000 0--- -000 u--- -uuu tb1c 0--- -000 0--- -000 0--- -000 u--- -uuu simtoc 0000 0000 0000 0000 0000 0000 uuuu uuuu simc0 111- 0000 111- 0000 111- 0000 uuu- uuuu simc1 1000 0001 1000 0001 1000 0001 uuuu uuuu simd xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu sima/ simc ? 0000 0000 0000 0000 0000 0000 uuuu uuuu ctm0c0 0000 0000 0000 0000 0000 0000 uuuu uuuu ctm0c1 0000 0000 0000 0000 0000 0000 uuuu uuuu ctm0dl 0000 0000 0000 0000 0000 0000 uuuu uuuu ctm0dh ---- --00 ---- --00 ---- --00 ---- --uu ctm0al 0000 0000 0000 0000 0000 0000 uuuu uuuu ctm0ah ---- --00 ---- --00 ---- --00 ---- --uu eea -000 0000 -000 0000 -000 0000 -uuu uuuu eed 0000 0000 0000 0000 0000 0000 uuuu uuuu pscr1 ---- --00 ---- --00 ---- --00 ---- --uu sledc --00 0000 --00 0000 --00 0000 --uu uuuu sledc 0000 0000 0000 0000 0000 0000 uuuu uuuu sledc1 ---- 0000 ---- 0000 ---- 0000 ---- uuuu ptmc0 0000 0--- 0000 0--- 0000 0--- uuuu u--- ptmc1 0000 0000 0000 0000 0000 0000 uuuu uuuu ptmdl 0000 0000 0000 0000 0000 0000 uuuu uuuu ptmdh ---- --00 ---- --00 ---- --00 ---- --uu ptmal 0000 0000 0000 0000 0000 0000 uuuu uuuu ptmah ---- --00 ---- --00 ---- --00 ---- --uu
rev. 1.40 9? de?e??e? 1?? ?01? rev. 1.40 93 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver register bs66f340 bs66f350 BS66F360 bs66f370 reset (power on) lvr reset (normal operation) wdt time-out (normal operation) wdt time-out (idle or sleep)* ptmrpl 0000 0000 0000 0000 0000 0000 uuuu uuuu ptmrph ---- --00 ---- --00 ---- --00 ---- --uu fc0 0000 0000 0000 0000 0000 0000 uuuu uuuu fc1 0000 0000 0000 0000 0000 0000 uuuu uuuu fc ? ---- ---0 ---- ---0 ---- ---0 ---- ---u farl 0000 0000 0000 0000 0000 0000 uuuu uuuu farh ---- 0000 ---- 0000 ---- 0000 ---- uuuu farh ---0 0000 ---0 0000 ---0 0000 ---u uuuu farh --00 0000 --00 0000 --00 0000 --uu uuuu farh -000 0000 -000 0000 -000 0000 -uuu uuuu fd0l 0000 0000 0000 0000 0000 0000 uuuu uuuu fd0h 0000 0000 0000 0000 0000 0000 uuuu uuuu fd1l 0000 0000 0000 0000 0000 0000 uuuu uuuu fd1h 0000 0000 0000 0000 0000 0000 uuuu uuuu fd ? l 0000 0000 0000 0000 0000 0000 uuuu uuuu fd ? h 0000 0000 0000 0000 0000 0000 uuuu uuuu fd3l 0000 0000 0000 0000 0000 0000 uuuu uuuu fd3h 0000 0000 0000 0000 0000 0000 uuuu uuuu stmc0 0000 0--- 0000 0--- 0000 0--- uuuu u--- stmc1 0000 0000 0000 0000 0000 0000 uuuu uuuu stmdl 0000 0000 0000 0000 0000 0000 uuuu uuuu stmdh 0000 0000 0000 0000 0000 0000 uuuu uuuu stmal 0000 0000 0000 0000 0000 0000 uuuu uuuu stmah 0000 0000 0000 0000 0000 0000 uuuu uuuu stmrp 0000 0000 0000 0000 0000 0000 uuuu uuuu ctm1c0 0000 0000 0000 0000 0000 0000 uuuu uuuu ctm1c1 0000 0000 0000 0000 0000 0000 uuuu uuuu ctm1dl 0000 0000 0000 0000 0000 0000 uuuu uuuu ctm1dh ---- --00 ---- --00 ---- --00 ---- --uu ctm1al 0000 0000 0000 0000 0000 0000 uuuu uuuu ctm1ah ---- --00 ---- --00 ---- --00 ---- --uu tsc0 010- ---- 010- ---- 010- ---- uuu- ---- tsc1 000- ---- 000- ---- 000- ---- uuu- ---- tsc ? 0000 0000 0000 0000 0000 0000 uuuu uuuu tsc3 --0- ---- --0- ---- --0- ---- --u- ---- pe --11 1111 --11 1111 --11 1111 --uu uuuu pe 1111 1111 1111 1111 1111 1111 uuuu uuuu pec --11 1111 --11 1111 --11 1111 --uu uuuu pec 1111 1111 1111 1111 1111 1111 uuuu uuuu pepu --00 0000 --00 0000 --00 0000 --uu uuuu pepu 0000 0000 0000 0000 0000 0000 uuuu uuuu pf --11 1111 --11 1111 --11 1111 --uu uuuu pfc --11 1111 --11 1111 --11 1111 --uu uuuu pfpu --00 0000 --00 0000 --00 0000 --uu uuuu usr 0000 1011 0000 1011 0000 1011 uuuu uuuu
rev. 1.40 94 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 9? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver register bs66f340 bs66f350 BS66F360 bs66f370 reset (power on) lvr reset (normal operation) wdt time-out (normal operation) wdt time-out (idle or sleep)* ucr1 0000 00x0 0000 00x0 0000 00x0 uuuu uuuu ucr ? 0000 0000 0000 0000 0000 0000 uuuu uuuu txr_rxr xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu brg xxxx xxxx xxxx xxxx xxxx xxxx uuuu uuuu pg 1111 1111 1111 1111 1111 1111 uuuu uuuu pgc 1111 1111 1111 1111 1111 1111 uuuu uuuu pgpu 0000 0000 0000 0000 0000 0000 uuuu uuuu tktmr 0000 0000 0000 0000 0000 0000 uuuu uuuu tkc0 0000 0-00 0000 0-00 0000 0-00 uuuu u-uu tk1 ? dl 0000 0000 0000 0000 0000 0000 uuuu uuuu tk1 ? dh 0000 0000 0000 0000 0000 0000 uuuu uuuu tkc1 0000 0011 0000 0011 0000 0011 uuuu uuuu tkm01 ? dl 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm01 ? dh 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm0rol 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm0roh ---- --00 ---- --00 ---- --00 ---- --uu tkm0c0 --00 0000 --00 0000 --00 0000 --uu uuuu tkm0c1 0-00 0000 0-00 0000 0-00 0000 u-uu uuuu tkm0c ? 1110 0100 1110 0100 1110 0100 uuuu uuuu tkm11 ? dl 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm11 ? dh 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm1rol 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm1roh ---- --00 ---- --00 ---- --00 ---- --uu tkm1c0 --00 0000 --00 0000 --00 0000 --uu uuuu tkm1c1 0-00 0000 0-00 0000 0-00 0000 u-uu uuuu tkm1c ? 1110 0100 1110 0100 1110 0100 uuuu uuuu tkm ? 1 ? dl 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm ? 1 ? dh 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm ? rol 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm ? roh ---- --00 ---- --00 ---- --00 ---- --uu tkm ? c0 --00 0000 --00 0000 --00 0000 --uu uuuu tkm ? c1 0-00 0000 0-00 0000 0-00 0000 u-uu uuuu tkm ? c ? 1110 0100 1110 0100 1110 0100 uuuu uuuu tkm31 ? dl 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm31 ? dh 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm3rol 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm3roh ---- --00 ---- --00 ---- --00 ---- --uu tkm3c0 --00 0000 --00 0000 --00 0000 --uu uuuu tkm3c1 0-00 0000 0-00 0000 0-00 0000 u-uu uuuu tkm3c ? 1110 0100 1110 0100 1110 0100 uuuu uuuu tkm41 ? dl 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm41 ? dh 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm4rol 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm4roh ---- --00 ---- --00 ---- --00 ---- --uu tkm4c0 --00 0000 --00 0000 --00 0000 --uu uuuu
rev. 1.40 94 de?e??e? 1?? ?01? rev. 1.40 9 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver register bs66f340 bs66f350 BS66F360 bs66f370 reset (power on) lvr reset (normal operation) wdt time-out (normal operation) wdt time-out (idle or sleep)* tkm4c1 0-00 0000 0-00 0000 0-00 0000 u-uu uuuu tkm4c ? 1110 0100 1110 0100 1110 0100 uuuu uuuu tkm ? 1 ? dl 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm ? 1 ? dh 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm ? rol 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm ? roh ---- --00 ---- --00 ---- --00 ---- --uu tkm ? c0 --00 0000 --00 0000 --00 0000 --uu uuuu tkm ? c1 0-00 0000 0-00 0000 0-00 0000 u-uu uuuu tkm ? c ? 1110 0100 1110 0100 1110 0100 uuuu uuuu tkm ? 1 ? dl 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm ? 1 ? dh 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm ? rol 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm ? roh ---- --00 ---- --00 ---- --00 ---- --uu tkm ? c0 --00 0000 --00 0000 --00 0000 --uu uuuu tkm ? c1 0-00 0000 0-00 0000 0-00 0000 u-uu uuuu tkm ? c ? 1110 0100 1110 0100 1110 0100 uuuu uuuu tkm71 ? dl 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm71 ? dh 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm7rol 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm7roh ---- --00 ---- --00 ---- --00 ---- --uu tkm7c0 --00 0000 --00 0000 --00 0000 --uu uuuu tkm7c1 0-00 0000 0-00 0000 0-00 0000 u-uu uuuu tkm7c ? 1110 0100 1110 0100 1110 0100 uuuu uuuu eec ---- 0000 ---- 0000 ---- 0000 ---- uuuu ifs --00 0000 --00 0000 --00 0000 --uu uuuu pas0 0000 0000 0000 0000 0000 0000 uuuu uuuu pas1 00-- 0000 00-- 0000 00-- 0000 uu-- uuuu pas1 ---- 0000 ---- 0000 ---- 0000 ---- uuuu pbs0 0000 0000 0000 0000 0000 0000 uuuu uuuu pbs1 0000 0000 0000 0000 0000 0000 uuuu uuuu pcs0 0000 0000 0000 0000 0000 0000 uuuu uuuu pcs1 0000 0000 0000 0000 0000 0000 uuuu uuuu pds0 0000 0000 0000 0000 0000 0000 uuuu uuuu pds1 0000 0000 0000 0000 0000 0000 uuuu uuuu pes0 0000 0000 0000 0000 0000 0000 uuuu uuuu pes0 0000 ---- 0000 ---- 0000 ---- uuuu ---- pes1 ---- 0000 ---- 0000 ---- 0000 ---- uuuu pes1 0000 0000 0000 0000 0000 0000 uuuu uuuu pfs0 ---- 0000 ---- 0000 ---- 0000 ---- uuuu pgs0 0000 0000 0000 0000 0000 0000 uuuu uuuu pgs1 0000 0000 0000 0000 0000 0000 uuuu uuuu ph --11 1111 --11 1111 --11 1111 --uu uuuu phc --11 1111 --11 1111 --11 1111 --uu uuuu phpu --00 0000 --00 0000 --00 0000 --uu uuuu tkm81 ? dl 0000 0000 0000 0000 0000 0000 uuuu uuuu
rev. 1.40 9 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 97 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver register bs66f340 bs66f350 BS66F360 bs66f370 reset (power on) lvr reset (normal operation) wdt time-out (normal operation) wdt time-out (idle or sleep)* tkm81 ? dh 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm8rol 0000 0000 0000 0000 0000 0000 uuuu uuuu tkm8roh ---- --00 ---- --00 ---- --00 ---- --uu tkm8c0 --00 0000 --00 0000 --00 0000 --uu uuuu tkm8c1 0-00 0000 0-00 0000 0-00 0000 u-uu uuuu tkm8c ? 1110 0100 1110 0100 1110 0100 uuuu uuuu note: "u" stands for unchanged "x" stands for "unknown" "-" stands for unimplemented
rev. 1.40 9? de?e??e? 1?? ?01? rev. 1.40 97 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver input/output ports holtek m icrocontrollers of fer c onsiderable fe xibility on t heir i/ o port s. w ith t he i nput or out put designation of every pin fully under user program control, pull-high selections for all ports and wake-up selections on certain pins, the user is provided with an i/o structure to meet the needs of a wide range of application possibilities. these d evices p rovide b idirectional i nput/output l ines l abeled wi th p ort n ames p a~ph. t hese i /o ports are mapped to the ram data memory with specifc addresses as shown in the special purpose data memory table. a ll of thes e i/o ports can be used for input and output operations. for input operation, these ports are non-latch ing, which means the inputs must be ready at the t2 rising edge of instruction "mov a, [m]", where m denotes the port address. for output operation, all the data is latched and remains unchanged until the output latch is rewritten. register name bit 7 6 5 4 3 2 1 0 pa pa7 pa ? pa ? pa4 pa3 pa ? pa1 pa0 pac pac7 pac ? pac ? pac4 pac3 pac ? pac1 pac0 papu papu7 papu ? papu ? papu4 papu3 papu ? papu1 papu0 pawu pawu7 pawu ? pawu ? pawu4 pawu3 pawu ? pawu1 pawu0 pb pb7 pb ? pb ? pb4 pb3 pb ? pb1 pb0 pbc pbc7 pbc ? pbc ? pbc4 pbc3 pbc ? pbc1 pbc0 pbpu pbpu7 pbpu ? pbpu ? pbpu4 pbpu3 pbpu ? pbpu1 pbpu0 pc pc3 pc ? pc1 pc0 pcc pcc3 pcc ? pcc1 pcc0 pcpu pcpu3 pcpu ? pcpu1 pcpu0 pe pe ? pe4 pe3 pe ? pe1 pe0 pec pec ? pec4 pec3 pec ? pec1 pec0 pepu pepu ? pepu4 pepu3 pepu ? pepu1 pepu0 i/o registers list C bs66f340 register name bit 7 6 5 4 3 2 1 0 pa pa7 pa ? pa ? pa4 pa3 pa ? pa1 pa0 pac pac7 pac ? pac ? pac4 pac3 pac ? pac1 pac0 papu papu7 papu ? papu ? papu4 papu3 papu ? papu1 papu0 pawu pawu7 pawu ? pawu ? pawu4 pawu3 pawu ? pawu1 pawu0 pb pb7 pb ? pb ? pb4 pb3 pb ? pb1 pb0 pbc pbc7 pbc ? pbc ? pbc4 pbc3 pbc ? pbc1 pbc0 pbpu pbpu7 pbpu ? pbpu ? pbpu4 pbpu3 pbpu ? pbpu1 pbpu0 pc pc7 pc ? pc ? pc4 pc3 pc ? pc1 pc0 pcc pcc7 pcc ? pcc ? pcc4 pcc3 pcc ? pcc1 pcc0 pcpu pcpu7 pcpu ? pcpu ? pcpu4 pcpu3 pcpu ? pcpu1 pcpu0 pd pd7 pd ? pd ? pd4 pd3 pd ? pd1 pd0 pdc pdc7 pdc ? pdc ? pdc4 pdc3 pdc ? pdc1 pdc0 pdpu pdpu7 pdpu ? pdpu ? pdpu4 pdpu3 pdpu ? pdpu1 pdpu0 pe pe7 pe ? pe ? pe4 pe3 pe ? pe1 pe0 pec pec7 pec ? pec ? pec4 pec3 pec ? pec1 pec0 pepu pepu7 pepu ? pepu ? pepu4 pepu3 pepu ? pepu1 pepu0 i/o registers list C bs66f350
rev. 1.40 98 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 99 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver register name bit 7 6 5 4 3 2 1 0 pa pa7 pa ? pa ? pa4 pa3 pa ? pa1 pa0 pac pac7 pac ? pac ? pac4 pac3 pac ? pac1 pac0 papu papu7 papu ? papu ? papu4 papu3 papu ? papu1 papu0 pawu pawu7 pawu ? pawu ? pawu4 pawu3 pawu ? pawu1 pawu0 pb pb7 pb ? pb ? pb4 pb3 pb ? pb1 pb0 pbc pbc7 pbc ? pbc ? pbc4 pbc3 pbc ? pbc1 pbc0 pbpu pbpu7 pbpu ? pbpu ? pbpu4 pbpu3 pbpu ? pbpu1 pbpu0 pc pc7 pc ? pc ? pc4 pc3 pc ? pc1 pc0 pcc pcc7 pcc ? pcc ? pcc4 pcc3 pcc ? pcc1 pcc0 pcpu pcpu7 pcpu ? pcpu ? pcpu4 pcpu3 pcpu ? pcpu1 pcpu0 pd pd7 pd ? pd ? pd4 pd3 pd ? pd1 pd0 pdc pdc7 pdc ? pdc ? pdc4 pdc3 pdc ? pdc1 pdc0 pdpu pdpu7 pdpu ? pdpu ? pdpu4 pdpu3 pdpu ? pdpu1 pdpu0 pe pe7 pe ? pe ? pe4 pe3 pe ? pe1 pe0 pec pec7 pec ? pec ? pec4 pec3 pec ? pec1 pec0 pepu pepu7 pepu ? pepu ? pepu4 pepu3 pepu ? pepu1 pepu0 pf pf ? pf4 pf3 pf ? pf1 pf0 pfc pfc ? pfc4 pfc3 pfc ? pfc1 pfc0 pfpu pfpu ? pfpu4 pfpu3 pfpu ? pfpu1 pfpu0 i/o registers list C BS66F360
rev. 1.40 98 de?e??e? 1?? ?01? rev. 1.40 99 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver register name bit 7 6 5 4 3 2 1 0 pa pa7 pa ? pa ? pa4 pa3 pa ? pa1 pa0 pac pac7 pac ? pac ? pac4 pac3 pac ? pac1 pac0 papu papu7 papu ? papu ? papu4 papu3 papu ? papu1 papu0 pawu pawu7 pawu ? pawu ? pawu4 pawu3 pawu ? pawu1 pawu0 pb pb7 pb ? pb ? pb4 pb3 pb ? pb1 pb0 pbc pbc7 pbc ? pbc ? pbc4 pbc3 pbc ? pbc1 pbc0 pbpu pbpu7 pbpu ? pbpu ? pbpu4 pbpu3 pbpu ? pbpu1 pbpu0 pc pc7 pc ? pc ? pc4 pc3 pc ? pc1 pc0 pcc pcc7 pcc ? pcc ? pcc4 pcc3 pcc ? pcc1 pcc0 pcpu pcpu7 pcpu ? pcpu ? pcpu4 pcpu3 pcpu ? pcpu1 pcpu0 pd pd7 pd ? pd ? pd4 pd3 pd ? pd1 pd0 pdc pdc7 pdc ? pdc ? pdc4 pdc3 pdc ? pdc1 pdc0 pdpu pdpu7 pdpu ? pdpu ? pdpu4 pdpu3 pdpu ? pdpu1 pdpu0 pe pe7 pe ? pe ? pe4 pe3 pe ? pe1 pe0 pec pec7 pec ? pec ? pec4 pec3 pec ? pec1 pec0 pepu pepu7 pepu ? pepu ? pepu4 pepu3 pepu ? pepu1 pepu0 pf pf ? pf4 pf3 pf ? pf1 pf0 pfc pfc ? pfc4 pfc3 pfc ? pfc1 pfc0 pfpu pfpu ? pfpu4 pfpu3 pfpu ? pfpu1 pfpu0 pg pg7 pg ? pg ? pg4 pg3 pg ? pg1 pg0 pgc pgc7 pgc ? pgc ? pgc4 pgc3 pgc ? pgc1 pgc0 pgpu pgpu7 pgpu ? pgpu ? pgpu4 pgpu3 pgpu ? pgpu1 pgpu0 ph ph ? ph4 ph3 ph ? ph1 ph0 phc phc ? phc4 phc3 phc ? phc1 phc0 phpu phpu ? phpu4 phpu3 phpu ? phpu1 phpu0 i/o registers list C bs66f370 unimplemented, read as "0". pawun : port a pin wake-up function control 0: disable 1: enable papun/pbpun/pcpun/pdpun/pepun/pfpun/pgpun/phpun : i/o pin pull-high function control 0: disable 1: enable pan/pbn/pcn/pdn/pen/pfn/pgn/phn : i/o port data bit 0: data 0 1: data 1 pacn/pbcn/pccn/pdcn/pecn/pfcn/pgcn/phcn : i/o pin type selection 0: output 1: input
rev. 1.40 100 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 101 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver pull-high resistors many product applications require pull-high resistors for their switch inputs usually requiring the use of an external resistor . t o eliminate the need for these external resistors, all i/o pins, when confgured as an input have the capability of being connected to an internal pull-high resistor . these pull-high resistors are selected using the relevant pull-high control registers and are implemented using w eak p mos transis tors. n ote that the pull-high res istor can be controlled by the relevant pull-high control register only when the pin-shared functional pin is selected as an input or nmos output. otherwise, the pull-high resistors can not be enabled. port a wake-up the hal t instruction forces the microcontroller into the sleep or idle mode which preserves power, a feature that is important for battery and other low-power applications. v arious methods exist to wake-up the microcontroller, one of which is to change the logic condition on one of the port a pins from high to low . this function is especially suitable for applications that can be woken up via extern al switches. each pin on port a can be selected individually to have this wake-up feature using the p awu register . note that the wake-up function can be controlled by the wake-up control registers only when the pin-shared functional pin is selected as general purpose input/output and the mcu enters the power down mode. i/o port control registers each po rt h as i ts o wn c ontrol r egister, k nown a s p ac~phc, wh ich c ontrols t he i nput/output configuration. w ith t his c ontrol re gister, e ach i/ o pi n wi th or wi thout pul l-high re sistors c an be reconfigured dynamically under software control. for the i/o pin to function as an input, the corresponding bit of the control register must be written as a "1". this will then allow the logic state of the input pin to be directly read by instructions. when the corresponding bit of the control register is written as a "0", the i/o pin will be setup as a cmos output. if the pin is currently setup as an output, instructions can still be used to read the output register. however, it should be noted that the program will in fact only read the status of the output data latch and not the actual logic status of the output pin. i/o port source current control these devices s upport dif ferent s ource current driving capability for each i/o port. w ith the selection register, sledc or sledc1, specifc i/o port can support four levels of the source current driving capability . users should refer to the d.c. characteristics sectio n to select the desired source current for different applications. register name bit 7 6 5 4 3 2 1 0 sledc (bs ?? f340) pcps1 pcps0 pbps1 pbps0 paps1 paps0 sledc (bs ?? f3 ? 0/bs ?? f3 ? 0/ bs ?? f370) pcps3 pcps ? pcps1 pcps0 pbps1 pbps0 paps1 paps0 sledc1 (bs ?? f370) phps1 phps0 pgps1 pgps0 i/o port source current control registers list
rev. 1.40 100 de?e??e? 1?? ?01? rev. 1.40 101 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver sledc register C bs66f340 bit 7 6 5 4 3 2 1 0 na ? e pcps1 pcps0 pbps1 pbps0 paps1 paps0 r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 bit 7~6 unimplemented, read as 0 bit 5~4 pcps1~pcps0 : pc3~pc0 source current selection 00: source current=level 0 (min.) 01: source current=level 1 10: source current=level 2 11: source current=level 3 (max.) bit 3~2 pbps1~pbps0 : pb7~pb4 source current selection 00: source current=level 0 (min.) 01: source current=level 1 10: source current=level 2 11: source current=level 3 (max.) bit 1~0 paps1~paps0 : pa7~pa5 and pa1 source current selection 00: source current=level 0 (min.) 01: source current=level 1 10: source current=level 2 11: source current=level 3 (max.) sledc register C bs66f350/BS66F360/bs66f370 bit 7 6 5 4 3 2 1 0 na ? e pcps3 pcps ? pcps1 pcps0 pbps1 pbps0 paps1 paps0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 pcps3~pcps2 : pc7~pc4 source current selection 00: source current=level 0 (min.) 01: source current=level 1 10: source current=level 2 11: source current=level 3 (max.) bit 5~4 pcps1~pcps0 : pc3~pc0 source current selection 00: source current=level 0 (min.) 01: source current=level 1 10: source current=level 2 11: source current=level 3 (max.) bit 3~2 pbps1~pbps0 : pb7~pb4 source current selection 00: source current=level 0 (min.) 01: source current=level 1 10: source current=level 2 11: source current=level 3 (max.) bit 1~0 paps1~paps0 : pa7~pa5 and pa1 source current selection 00: source current=level 0 (min.) 01: source current=level 1 10: source current=level 2 11: source current=level 3 (max.)
rev. 1.40 10 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 103 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver sledc1 register C bs66f370 bit 7 6 5 4 3 2 1 0 na ? e phps1 phps0 pgps1 pgps0 r/w r/w r/w r/w r/w por 0 0 0 0 bit 7~4 unimplemented, read as 0. bit 3~2 phps1~phps0 : ph3~ph0 source current selection 00: source current = level 0 (min.) 01: source current = level 1 10: source current = level 2 11: source current = level 3 (max.) bit 1~0 pgps1~pgps0 : pg3~pg0 source current selection 00: source current = level 0 (min.) 01: source current = level 1 10: source current = level 2 11: source current = level 3 (max.) pin-shared functions the fexibility of the microcontroller range is greatly enhanced by the use of pins that have more than one function. limited numbers of pins can force serious design constraints on designers but by supplying pins with multi-functions , many of these diffculties can be overcome. for these pins, the desired function of the multi-functio n i/o pins is selected by a series of registers via the application program control. pin-shared function selection registers the limited number of supplied pins in a package can i mpose restrictions on the amount of functions a certain device can contain. however by allowing the same pins to share several dif ferent functions and providing a means of function selection, a wide range of dif ferent functions can be incorporated into even relatively small package sizes. each device includes port "x" output function selection register "n", labeled as pxsn, and input function selection register , labeled as ifs, which can select the desired functions of the multi-function pin-shared pins. when t he pi n-shared i nput funct ion i s se lected t o be use d, t he c orresponding i nput a nd output functions selection should be properly managed. for example, if the i 2 c sda line is used, the corresponding output pin-shared function should be configured as the sdi/sda function by configuring the pxsn regis ter and the sda signal intput should be properly selected using the ifs re gister. howe ver, i f t he e xternal i nterrupt func tion i s se lected t o be use d, t he re levant out put pin-shared function should be selected as an i/o function and the interrupt input signal should be selected. the m ost i mportant p oint t o n ote i s t o m ake su re t hat t he d esired p in-shared f unction i s p roperly selected and also deselected. t o select the desired pin-shared function, the pin-shared function should frst be correctly selected using the corresponding pin-shared control register . after that the corresponding peripheral functional setting should be confgured and then the peripheral function can be enabled. t o correctly deselect the pin-shared function, the peripheral function should frst be disabled and then the corresponding pin-shared function control register can be modifed to select other pin-shared functions.
rev. 1.40 10? de?e??e? 1?? ?01? rev. 1.40 103 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver register name bit 7 6 5 4 3 2 1 0 pas0 pas07 pas0 ? pas0 ? pas04 pas03 pas0 ? pas01 pas00 pas1 pas17 pas1 ? pas13 pas1 ? pas11 pas10 pbs0 pbs07 pbs0 ? pbs0 ? pbs04 pbs03 pbs0 ? pbs01 pbs00 pbs1 pbs17 pbs1 ? pbs1 ? pbs14 pbs13 pbs1 ? pbs11 pbs10 pcs0 pcs07 pcs0 ? pcs0 ? pcs04 pcs03 pcs0 ? pcs01 pcs00 pes0 pes07 pes0 ? pes0 ? pes04 pes03 pes0 ? pes01 pes00 pes1 pes13 pes1 ? pes11 pes10 ifs ifs ? ifs4 ifs3 ifs ? ifs1 ifs0 pin-shared function selection registers list C bs66f340 register name bit 7 6 5 4 3 2 1 0 pas0 pas07 pas0 ? pas0 ? pas04 pas03 pas0 ? pas01 pas00 pas1 pas13 pas1 ? pas11 pas10 pbs0 pbs07 pbs0 ? pbs0 ? pbs04 pbs03 pbs0 ? pbs01 pbs00 pbs1 pbs17 pbs1 ? pbs1 ? pbs14 pbs13 pbs1 ? pbs11 pbs10 pcs0 pcs07 pcs0 ? pcs0 ? pcs04 pcs03 pcs0 ? pcs01 pcs00 pcs1 pcs17 pcs1 ? pcs1 ? pcs14 pcs13 pcs1 ? pcs11 pcs10 pds0 pds07 pds0 ? pds0 ? pds04 pds03 pds0 ? pds01 pds00 pds1 pds17 pds1 ? pds1 ? pds14 pds13 pds1 ? pds11 pds10 pes0 pes07 pes0 ? pes0 ? pes04 pes1 pes17 pes1 ? pes1 ? pes14 pes13 pes1 ? pes11 pes10 ifs ifs ? ifs4 ifs3 ifs ? ifs1 ifs0 pin-shared function selection registers list C bs66f350 register name bit 7 6 5 4 3 2 1 0 pas0 pas07 pas0 ? pas0 ? pas04 pas03 pas0 ? pas01 pas00 pas1 pas13 pas1 ? pas11 pas10 pbs0 pbs07 pbs0 ? pbs0 ? pbs04 pbs03 pbs0 ? pbs01 pbs00 pbs1 pbs17 pbs1 ? pbs1 ? pbs14 pbs13 pbs1 ? pbs11 pbs10 pcs0 pcs07 pcs0 ? pcs0 ? pcs04 pcs03 pcs0 ? pcs01 pcs00 pcs1 pcs17 pcs1 ? pcs1 ? pcs14 pcs13 pcs1 ? pcs11 pcs10 pds0 pds07 pds0 ? pds0 ? pds04 pds03 pds0 ? pds01 pds00 pds1 pds17 pds1 ? pds1 ? pds14 pds13 pds1 ? pds11 pds10 pes0 pes07 pes0 ? pes0 ? pes04 pes03 pes0 ? pes01 pes00 pes1 pes17 pes1 ? pes1 ? pes14 pes13 pes1 ? pes11 pes10 pfs0 pfs03 pfs0 ? pfs01 pfs00 ifs ifs ? ifs4 ifs3 ifs ? ifs1 ifs0 pin-shared function selection registers list C BS66F360
rev. 1.40 104 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 10? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver register name bit 7 6 5 4 3 2 1 0 pas0 pas07 pas0 ? pas0 ? pas04 pas03 pas0 ? pas01 pas00 pas1 pas13 pas1 ? pas11 pas10 pbs0 pbs07 pbs0 ? pbs0 ? pbs04 pbs03 pbs0 ? pbs01 pbs00 pbs1 pbs17 pbs1 ? pbs1 ? pbs14 pbs13 pbs1 ? pbs11 pbs10 pcs0 pcs07 pcs0 ? pcs0 ? pcs04 pcs03 pcs0 ? pcs01 pcs00 pcs1 pcs17 pcs1 ? pcs1 ? pcs14 pcs13 pcs1 ? pcs11 pcs10 pds0 pds07 pds0 ? pds0 ? pds04 pds03 pds0 ? pds01 pds00 pds1 pds17 pds1 ? pds1 ? pds14 pds13 pds1 ? pds11 pds10 pes0 pes07 pes0 ? pes0 ? pes04 pes03 pes0 ? pes01 pes00 pes1 pes17 pes1 ? pes1 ? pes14 pes13 pes1 ? pes11 pes10 pfs0 pfs03 pfs0 ? pfs01 pfs00 pgs0 pgs07 pgs0 ? pgs0 ? pgs04 pgs03 pgs0 ? pgs01 pgs00 pgs1 pgs17 pgs1 ? pgs1 ? pgs14 pgs13 pgs1 ? pgs11 pgs10 ifs ifs ? ifs4 ifs3 ifs ? ifs1 ifs0 pin-shared function selection registers list C bs66f370 ? pas0 register bit 7 6 5 4 3 2 1 0 na ? e pas07 pas0 ? pas0 ? pas04 pas03 pas0 ? pas01 pas00 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 pas07~pas06 : pa3 pin function selection 00/11: pa3 01: scs 10: xt1 bit 5~4 pas05~pas04 : pa2 pin function selection pas0[5:4] bs66f340 bs66f350 BS66F360 bs66f370 00 pa ? /ctck1 pa ? pa ? pa ? 01 scs scs scs scs 10 pa ? /ctck1 pa ? pa ? pa ? 11 pa ? /ctck1 pa ? pa ? pa ? bit 3~2 pas03~pas02 : pa1 pin function selection 00/10/11: pa1 01: ctp0 bit 1~0 pas01~pas00 : pa0 pin function selection 00/10/11: pa0 01: sdo
rev. 1.40 104 de?e??e? 1?? ?01? rev. 1.40 10 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? pas1 register C bs66f340 bit 7 6 5 4 3 2 1 0 na ? e pas17 pas1 ? pas13 pas1 ? pas11 pas10 r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 bit 7~6 pas17~pas16 : pa7 pin function selection 00/10/11: pa7 01: ctp1 bit 5~4 unimplemented, read as 0 bit 3~2 pas13~pas12 : pa5 pin function selection 00/10/11: pa5 01: ctp0b bit 1~0 pas11~pas10 : pa4 pin function selection 00/11: pa4 01: sdo 10: xt2 ? pas1 register C bs66f350/BS66F360/bs66f370 bit 7 6 5 4 3 2 1 0 na ? e pas13 pas1 ? pas11 pas10 r/w r/w r/w r/w r/w por 0 0 0 0 bit 7~4 unimplemented, read as 0 bit 3~2 pas13~pas12 : pa5 pin function selection 00/10/11: pa5 01: ctp0b bit 1~0 pas11~pas10 : pa4 pin function selection 00/11: pa4 01: sdo 10: xt2 ? pbs0 register bit 7 6 5 4 3 2 1 0 na ? e pbs07 pbs0 ? pbs0 ? pbs04 pbs03 pbs0 ? pbs01 pbs00 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 pbs07~pbs06 : pb3 pin function selection 00/10: pb3 01: rx 11: an3 bit 5~4 pbs05~pbs04 : pb2 pin function selection 00: pb2/ptpi 01: tx 10: ptp 11: an2 bit 3~2 pbs03~pbs02 : pb1 pin function selection 00/10: pb1 01: sck/scl 11: an1 bit 1~0 pbs01~pbs00 : pb0 pin function selection 00: pb0 01: sdi/sda 10: vref 11: an0
rev. 1.40 10 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 107 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? pbs1 register bit 7 6 5 4 3 2 1 0 na ? e pbs17 pbs1 ? pbs1 ? pbs14 pbs13 pbs1 ? pbs11 pbs10 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 pbs17~pbs16 : pb7 pin function selection 00/01: pb7/int1 10: key4 11: an7 bit 5~4 pbs15~pbs14 : pb6 pin function selection 00/01: pb6/ptck 10: key3 11: an6 bit 3~2 pbs13~pbs12 : pb5 pin function selection 00/01: pb5/stck 10: key2 11: an5 bit 1~0 pbs11~pbs10 : pb4 pin function selection 00: pb4/ptpi 01: ptpb 10: key1 11: an4 ? pcs0 register bit 7 6 5 4 3 2 1 0 na ? e pcs07 pcs0 ? pcs0 ? pcs04 pcs03 pcs0 ? pcs01 pcs00 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 pcs07~pcs06 : pc3 pin function selection 00: pc3 01: pc3 10: key8 11: pc3 bit 5~4 pcs05~pcs04 : pc2 pin function selection 00: pc2 01: pc2 10: key7 11: pc2 bit 3~2 pcs03~pcs02 : pc1 pin function selection 00: pc1 01: pc1 10: key6 11: pc1 bit 1~0 pcs01~pcs00 : pc0 pin function selection 00: pc0 01: pc0 10: key5 11: pc0
rev. 1.40 10? de?e??e? 1?? ?01? rev. 1.40 107 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? pcs1 register C bs66f350/BS66F360/bs66f370 bit 7 6 5 4 3 2 1 0 na ? e pcs17 pcs1 ? pcs1 ? pcs14 pcs13 pcs1 ? pcs11 pcs10 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 pcs17~pcs16 : pc7 pin function selection 00: pc7 01: pc7 10: key12 11: pc7 bit 5~4 pcs15~pcs14 : pc6 pin function selection 00: pc6 01: pc6 10: key11 11: pc6 bit 3~2 pcs13~pcs12 : pc5 pin function selection 00: pc5 01: pc5 10: key10 11: pc5 bit 1~0 pcs11~pcs10 : pc4 pin function selection 00: pc4 01: pc4 10: key9 11: pc4 ? pds0 register C bs66f350/BS66F360/bs66f370 bit 7 6 5 4 3 2 1 0 na ? e pds07 pds0 ? pds0 ? pds04 pds03 pds0 ? pds01 pds00 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 pds07~pds06 : pd3 pin function selection 00: pd3 01: pd3 10: key16 11: pd3 bit 5~4 pds05~pds04 : pd2 pin function selection 00: pd2 01: pd2 10: key15 11: pd2 bit 3~2 pds03~pds02 : pd1 pin function selection 00: pd1 01: pd1 10: key14 11: pd1 bit 1~0 pds01~pds00 : pd0 pin function selection 00: pd0 01: pd0 10: key13 11: pd0
rev. 1.40 108 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 109 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? pds1 register C bs66f350/BS66F360/bs66f370 bit 7 6 5 4 3 2 1 0 na ? e pds17 pds1 ? pds1 ? pds14 pds13 pds1 ? pds11 pds10 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 pds17~pds16 : pd7 pin function selection 00: pd7 01: pd7 10: key20 11: pd7 bit 5~4 pds15~pds14 : pd6 pin function selection 00: pd6 01: pd6 10: key19 11: pd6 bit 3~2 pds13~pds12 : pd5 pin function selection 00: pd5 01: pd5 10: key18 11: pd5 bit 1~0 pds11~pds10 : pd4 pin function selection 00: pd4 01: pd4 10: key17 11: pd4 ? pes0 register bit 7 6 5 4 3 2 1 0 na ? e pes07 pes0 ? pes0 ? pes04 pes03 pes0 ? pes01 pes00 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 pes07~pes06 : pe3 pin function selection pes0[7:6] bs66f340 bs66f350 BS66F360 bs66f370 00 pe3/stpi pe3/stpi pe3/stpi pe3/stpi 01 stpb stpb stpb stpb 10 key1 ? pe3/stpi key ? 4 key ? 4 11 pe3/stpi pe3/stpi pe3/stpi pe3/stpi bit 5~4 pes05~pes04 : pe2 pin function selection pes0[5:4] bs66f340 bs66f350 BS66F360 bs66f370 00 pe ? /stpi pe ? /stpi pe ? /stpi pe ? /stpi 01 stp stp stp stp 10 key11 pe ? /stpi key ? 3 key ? 3 11 pe ? /stpi pe ? /stpi pe ? /stpi pe ? /stpi bit 3~2 pes03~pes02 : pe1 pin function selection pes0[3:2] bs66f340 bs66f350 BS66F360 bs66f370 00 pe1 pe1 pe1 01 pe1 pe1 pe1 10 key10 key ?? key ?? 11 pe1 pe1 pe1 "": unimplemented, read as 0 C bs66f350
rev. 1.40 108 de?e??e? 1?? ?01? rev. 1.40 109 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 1~0 pes01~pes00 : pe0 pin function selection pes0[1:0] bs66f340 bs66f350 BS66F360 bs66f370 00 pe0 pe0 pe0 01 pe0 pe0 pe0 10 key9 key ? 1 key ? 1 11 pe0 pe0 pe0 unimplemented, read as 0 C bs66f350 ? pes1 register bit 7 6 5 4 3 2 1 0 na ? e pes17 pes1 ? pes1 ? pes14 pes13 pes1 ? pes11 pes10 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 pes17~pes16 : pe7 pin function selection pes1[7:6] bs66f340 bs66f350 BS66F360 bs66f370 00 pe7 pe7 pe7 01 ctp1b ctp1b ctp1b 10 pe7 key ?? key ?? 11 pe7 pe7 pe7 unimplemented, read as 0 C bs66f340 bit 5~4 pes15~pes14 : pe6 pin function selection pes1[5:4] bs66f340 bs66f350 BS66F360 bs66f370 00 pe ? pe ? pe ? 01 ctp1 ctp1 ctp1 10 pe ? key ?? key ?? 11 pe ? pe ? pe ? unimplemented, read as 0 C bs66f340 bit 3~2 pes13~pes12 : pe5 pin function selection pes1[3:2] bs66f340 bs66f350 BS66F360 bs66f370 00 pe ? pe ? /ctck1 pe ? /ctck1 pe ? /ctck1 01 ctp1b pe ? /ctck1 pe ? /ctck1 pe ? /ctck1 10 osc ? osc ? osc ? osc ? 11 pe ? pe ? /ctck1 pe ? /ctck1 pe ? /ctck1 bit 1~0 pes11~pes10 : pe4 pin function selection 00: pe4 01: pe4 10: osc1 11: pe4 ? pfs0 register C BS66F360/bs66f370 bit 7 6 5 4 3 2 1 0 na ? e pfs03 pfs0 ? pfs01 pfs00 r/w r/w r/w r/w r/w por 0 0 0 0 bit 7~4 unimplemented, read as 0 bit 3~2 pfs03~pfs02 : pf1 pin function selection 00/01/11: pf1 10: key28
rev. 1.40 110 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 111 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 1~0 pfs01~pfs00 : pf0 pin function selection 00/01/11: pf1 10: key27 ? pgs0 register C bs66f370 bit 7 6 5 4 3 2 1 0 na ? e pgs07 pgs0 ? pgs0 ? pgs04 pgs03 pgs0 ? pgs01 pgs00 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 pgs07~pgs06 : pg3 pin function selection 00: pg3 01: pg3 10: key32 11: pg3 bit 5~4 pgs05~pgs04 : pg2 pin function selection 00: pg2 01: pg2 10: key31 11: pg2 bit 3~2 pgs03~pgs02 : pg1 pin function selection 00: pg1 01: pg1 10: key30 11: pg1 bit 1~0 pgs01~pgs00 : pg0 pin function selection 00: pg0 01: pg0 10: key29 11: pg0 ? pgs1 register C bs66f370 bit 7 6 5 4 3 2 1 0 na ? e pgs17 pgs1 ? pgs1 ? pgs14 pgs13 pgs1 ? pgs11 pgs10 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 pgs17~pgs16 : pg7 pin function selection 00: pg7 01: pg7 10: key36 11: pg7 bit 5~4 pgs15~pgs14 : pg6 pin function selection 00: pg6 01: pg6 10: key35 11: pg6 bit 3~2 pgs13~pgs12 : pg5 pin function selection 00: pg5 01: pg5 10: key34 11: pg5 bit 1~0 pgs11~pgs10 : pg4 pin function selection 00: pg4 01: pg4 10: key33 11: pg4
rev. 1.40 110 de?e??e? 1?? ?01? rev. 1.40 111 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? ifs register bit 7 6 5 4 3 2 1 0 na ? e ifs ? ifs4 ifs3 ifs ? ifs1 ifs0 r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 bit 7~6 unimplemented, read as 0 bit 5~4 ifs5~ifs4 : scs input source pin selection 00/10: pa2 01/11: pa3 bit 3~2 ifs3~ifs2 : ptpi input source pin selection 00/10: pb2 01/11: pb4 bit 1~0 ifs1~ifs0 : stpi input source pin selection 00/01: pe2 01/11: pe3 i/o pin structures the accompanying diagrams illustrate the internal structures of some generic i/o pin types. as the exact logical construction of the i/o pin will dif fer from these drawings, they are supplied as a guide only to assist with the functional understanding of the i/o pins. the wide range of pin-shared structures does not permit all types to be shown.                    
                                           
                       ???     ??     ?   ?  ?          generic input/output structure
rev. 1.40 11 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 113 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver                        
                         
                         ?    ?  
 ?  ?          ?   ? -  ?  ? -  ?  ? ?        ? a/d input/output structure programming considerations within the user program, one of the things frs t to consider is port initialisation. after a res et, all of the i/o data and port control registers will be set to high. this means that all i/o pins will be defaulted to an input state, the level of which depends on the other connected circuitry and whether pull-high selections have been chosen. if the port control registers are then programmed to setup some pins as outputs, these output pins will have an initial high output value unless the associated port data registers are frst programmed. selecting which pins are inputs and which are outputs can be achieved byte-wide by loading the correct values into the appropriate port control register or by programming individual bits in the port control register using the "set [m].i" and "clr [m].i" instructions. note that when using these bit control instructions, a read-modify-write operation takes place. the microcontroller must frst read in the data on the entire port, modify it to the required new bit values and then rewrite this data back to the output ports. port a has the additional capability of providing wake-up functions. when the device is in the sleep or idle mode, various methods are available to wake the device up. one of these is a high to low transition of any of the port a pins. single or multiple pins on port a can be setup to have this function.
rev. 1.40 11 ? de?e??e? 1?? ?01? rev. 1.40 113 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver timer modules C tm one of the most fundamental functions in any microcontroller devices is the ability to control and measure time. t o implement time related functions the device includes several t imer modules, generally abbrevia ted to the name tm. the tms are multi-purpose timi ng units and serve to provide operations such as t imer/counter, input capture, compare match output and single pulse output as we ll a s be ing t he fun ctional uni t for t he ge neration of pw m si gnals. e ach of t he t ms ha s t wo interrupts. the addition of input and output pins for each tm ensures that users are provided with timing units with a wide and fexible range of features. the common features of the dif ferent tm types are described here with more detailed information provided in the individual compact, standard and periodic tm sections. introduction these de vices c ontain four t ms a nd e ach i ndividual t m c an be c ategorised a s a c ertain t ype, namely c ompact t ype t m, st andard t ype t m o r pe riodic t ype t m. al though si milar i n n ature, the dif ferent tm types vary in their feature complexity . the common features to all of the compact, standard and periodic tms will be described in this section and the detailed operation regarding each of the tm types will be described in separate sections. the main features and dif ferences between the three types of tms are summarised in the accompanying table. tm function ctm stm ptm ti ? e ? /counte ? input captu ? e co ? pa ? e mat ? h output pwm channels 1 1 1 single pulse output 1 1 pwm align ? ent edge edge edge pwm adjust ? ent pe ? iod & duty duty o ? pe ? iod duty o ? pe ? iod duty o ? pe ? iod tm function summary tm operation the dif ferent types of tm of fer a diverse range of functions, from simple timing operations to pwm signal generation. the key to understanding how the tm operates is to see it in terms of a free running count-up counter whose value is then compared with the value of pre-programmed internal comparators. w hen t he f ree r unning c ount-up c ounter h as t he sa me v alue a s t he p re-programmed comparator, known a s a c ompare m atch si tuation, a t m i nterrupt si gnal wi ll be ge nerated whi ch can clear the counter and perhaps also change the condition of the tm output pin. the internal tm counter is driven by a user selectable clock source, which can be an internal clock or an external pin. tm clock source the clock source which drives the main counter in each tm can originate from various sources. the selection of the required clock source is implemented using the xtnck2~xtnck0 bits in the xtmn control registers, where "x" stands for c, s or p type tm and "n" stands for the specifc tm serial number. fo r st m a nd pt m t here i s n o se rial n umber "n" i n t he r elevant p in o r c ontrol b its si nce there is only one stm and ptm respectively in the series of devices, the clock source can be a ratio of the system clock, f sys , or the internal high clock, f h , the f sub clock source or the external xtckn pin. the xtckn pin clock source is used to allow an external signal to drive the tm as an external clock source for event counting.
rev. 1.40 114 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 11 ? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver tm interrupts the compact, standard or periodic type tm has two internal interrupt, one for each of the internal comparator a or comparator p , which generate a tm interrupt when a compare match condition occurs. when a tm interrupt is generated, it can be used to clear the counter and also to change the state of the tm output pin. tm external pins each of the tms, irrespective of what type, has one or two tm input pins, with the label xtckn and xtpni respectivel y. the xtmn input pin, xtckn, is essentially a clock source for the xtmn and is selected using the xtnck2~xtnck0 bits in the xtmnc0 register. this external tm input pin allows an external clock source to drive the internal tm. the xtckn input pin can be chosen to have either a rising or falling active edge. the stck and ptck pins are also used as the external trigger input pin in single pulse output mode for the stm and ptm respectively. the other xtm input pin, stpi or ptpi, is the capture input whose acti ve edge can be a rising edge, a falling edge or both rising and falling edges and the active edge transition type is selected using the st io1~stio0 o r pt io1~ptio0 b its i n t he st mc1 o r pt mc1 r egister r espectively. t here i s another capture input, ptck, for ptm capture input mode, which can be used as the external trigger input source except the ptpi pin. the tm s each have tw o output pins , xtp n and xtp nb. the xtp nb is the inverted s ignal of the xtpn output. the tm output pins can be selected using the corresponding pin-shared function selection bits described in the pin-shared function section. when the tm is in the compare match output mode, these pins can be controlled by the tm to switch to a high or low level or to toggle when a c ompare m atch si tuation oc curs. t he e xternal xt pn or xt pnb ou tput pi n i s a lso t he pi n where the tm generates the pwm output waveform. as the tm output pins are pin-shared with other functions, the tm output function must first be setup using relevant pin-shared function selection register. device ctm stm ptm input output input output input output bs ?? f340 bs ?? f3 ? 0 bs ?? f3 ? 0 bs ?? f370 ctck0 ctck1 ctp0 ? ctp0b ctp1 ? ctp1b stck ? stpi stp ? stpb ptck ? ptpi ptp ? ptpb tm external pins
rev. 1.40 114 de?e??e? 1?? ?01? rev. 1.40 11 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver tm input/output pin selection selecting t o ha ve a t m i nput/output or whe ther t o re tain i ts ot her sha red func tion i s i mplemented using t he r elevant p in-shared f unction se lection r egisters, wi th t he c orresponding se lection b its i n each pin-shared function register corresponding to a tm input/output pin. confguring the selection bits correctly will setup the corresponding pin as a tm input/output. the details of the pin-shared function selection are described in the pin-shared function section. ctm n c tck n c tp n ccr output c tp nb ctm function pin control block diagram C n = 0 or 1 s tm stck stp stpi ccr ?aptu?e input ccr output s tp b stm fun?tion pin cont?ol blo?k diag?a? p tm p tck ptp pt pi ccr ?aptu?e input ccr output ptpb ptm fun?tion pin cont?ol blo?k diag?a?
rev. 1.40 11 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 117 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver programming considerations the tm counter registers and the capture/compare ccra and ccrp registers, all have a low and high byte structure. the high bytes can be directly accessed, but as the low bytes can only be accessed via an internal 8-bit buf fer, reading or writing to these registe r pairs must be carried out in a specifc way . the important point to note is that data transfer to and from the 8-bit buf fer and its related l ow b yte o nly t akes p lace wh en a wr ite o r r ead o peration t o i ts c orresponding h igh b yte i s executed. as the ccra and ccrp registers are implemented in the way shown in the following diagram and accessing these register pairs is carried out in a specifc way as described above, it is recommended to us e the " mov" instruction to access the ccra and ccrp low byte registers, named xtmnal and pt mrpl, usi ng t he fol lowing a ccess proc edures. ac cessing t he ccra or ccrb l ow byt e registers without following these access procedures will result in unpredictable values. data bus 8- ?it buffe? xtmndh xtmndl xtmnah xtmnal xtmn counte? registe? ( read only ) xtmn ccra registe? ( read / w?ite ) ptmrph ptmrpl ptm ccrp registe? ( read / w?ite ) 7kh iroorzlqj vwhsv vkrz wkh uhdg dqg zulwh surfhgxuhv :ulwlqj 'dwd wr &&? ru &&?3 ? step 1. w rite data to low byte xtmnal or ptmrpl C note that here data is only written to the 8-bit buffer. ? step 2. w rite data to high byte xtmnah or ptmrph C here data is written directly to the high byte regis ters and simultaneously data is latched from the 8-bit buffer to the low byte registers. ? reading data from the counter registers and ccra or ccrp ? step 1. read data from the high byte xtmndh, xtmnah or ptmrph C here d ata i s r ead d irectly f rom t he hi gh b yte r egisters a nd si multaneously d ata i s l atched from the low byte register into the 8-bit buffer. ? step 2. read data from the low byte xtmndl, xtmnal or ptmrpl C this step reads data from the 8-bit buffer.
rev. 1.40 11 ? de?e??e? 1?? ?01? rev. 1.40 117 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver compact type tm C ctm although the simplest form of the tm types, the compact tm type still contains three operating modes, wh ich a re c ompare ma tch ou tput, t imer/event c ounter a nd pw m ou tput m odes. t he compact tm can also be controlled with an external input pin and can drive two external output pin. device ctm core ctm input pin ctm output pin note bs ?? f340 bs ?? f3 ? 0 bs ?? f3 ? 0 bs ?? f370 10- ? it ctm (ctm0 ? ctm1) ctck0 ? ctck1 ctp0 ? ctp0b ctp1 ? ctp1b n = 0 ~ 1 f sys f sys /4 f h / ?4 f h / 1? f sub ctckn 000 001 010 011 100 101 110 111 ctnck ?~ ctnck 0 10 - ?it count - up counte? 3- ?it co?pa?ato? p ccrp ?7~?9 ?0~?9 10- ?it co?pa?ato? a ctnon ctnpau co?pa?ato? a mat?h co?pa?ato? p mat?h counte? clea? 0 1 output cont?ol pola?ity cont?ol pin cont?ol ctpn ctnoc ctnm 1 ? ctnm 0 ctnio 1 ? ctnio 0 ctmnaf inte??upt ctmnpf inte??upt ctnpol pxsn ccra ctncclr f sub ctpnb compact type tm block diagram C n = 0 or 1 compact tm operation the compact tm core is a 10-bit count-up counter which is driven by a user selectable internal or external clock source. there are also two internal comparators with the names, comparator a and comparator p . these comparators will compare the value in the counter with ccrp and ccra registers. the ccrp is three-bit w ide w hose value is compared w ith the highes t three bits in the counter while the ccra is ten-bit wide and therefore compares with all counter bits. the onl y way of changing the value of the 10-bit counte r using the appl ication program , is to clear t he c ounter by c hanging t he ct non bi t from l ow t o hi gh. t he c ounter wi ll a lso be c leared automatically by a counter overfow or a compare match with one of its associated comparators. when these conditions occur , a tm interrupt signal will also usually be generated. the compact type tm can operate in a number of dif ferent operational modes, can be driven by dif ferent clock sources including an input pin and can also control an output pin. all operating setup conditions are selected using relevant internal registers.
rev. 1.40 118 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 119 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver compact type tm register description overall operation of the compact tm is controlled using a series of registers. a read only register pair e xists t o st ore t he i nternal c ounter 10 -bit va lue, whi le a re ad/write re gister pa ir e xists t o st ore the internal 10-bit ccra value. the remaining two registers are control registers which setup the different operating and control modes and as well as the three ccrp bits. register name bit 7 6 5 4 3 2 1 0 ctmnc0 ctnpau ctnck ? ctnck1 ctnck0 ctnon ctnrp ? ctnrp1 ctnrp0 ctmnc1 ctnm1 ctnm0 ctnio1 ctnio0 ctnoc ctnpol ctndpx ctncclr ctmndl d7 d ? d ? d4 d3 d ? d1 d0 ctmndh d9 d8 ctmnal d7 d ? d ? d4 d3 d ? d1 d0 ctmnah d9 d8 10-bit compact tm registers list C n = 0 or 1 ctmndl register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r r r r r r r r por 0 0 0 0 0 0 0 0 bit 7~0 ctmn counter low byte register bit 7 ~ bit 0 ctmn 10-bit counter bit 7 ~ bit 0 ctmndh register bit 7 6 5 4 3 2 1 0 na ? e d9 d8 r/w r r por 0 0 bit 7~2 unimplemented, read as "0" bit 1~0 ctmn counter high byte register bit 1 ~ bit 0 ctmn 10-bit counter bit 9 ~ bit 8 ctmnal register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 ctmn ccra low byte register bit 7 ~ bit 0 ctmn 10-bit ccra bit 7 ~ bit 0 ctmnah register bit 7 6 5 4 3 2 1 0 na ? e d9 d8 r/w r/w r/w por 0 0 bit 7~2 unimplemented, read as "0" bit 1~0 ctmn ccra high byte register bit 1 ~ bit 0 ctmn 10-bit ccra bit 9 ~ bit 8
rev. 1.40 118 de?e??e? 1?? ?01? rev. 1.40 119 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ctmnc0 register bit 7 6 5 4 3 2 1 0 na ? e ctnpau ctnck ? ctnck1 ctnck0 ctnon ctnrp ? ctnrp1 ctnrp0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7 ctnpau : ctmn counter pause control 0: run 1: pause the c ounter c an be pa used by se tting t his bi t hi gh. cl earing t he bi t t o z ero re stores normal counter operation. when in a pause condition the ctmn will remain powered up a nd c ontinue t o c onsume po wer. t he c ounter wi ll re tain i ts re sidual va lue whe n this bit changes from low to high and res ume counting from this value w hen the bit changes to a low value again. bit 6~4 ctnck2~ctnck0 : select ctmn counter clock 000: f sys /4 001: f sys 010: f h /16 011: f h /64 100: f sub 101: f sub 110: ctckn rising edge clock 111: ctckn falling edge clock these t hree bi ts a re use d t o se lect t he c lock sourc e for t he ct mn. t he e xternal pi n clock source can be chosen to be active on the rising or falling edge. the clock source f sys is the system clock, while f h and f sub are other internal clocks, the details of which can be found in the oscillator section. bit 3 ctnon : ctmn counter on/off control 0: off 1: on this bi t c ontrols t he ove rall on /off fun ction of t he ct mn. se tting t he bi t hi gh e nables the counter to run while clearing the bit disables the ctmn. clearing this bit to zero will stop the counter from counting and turn of f the ctmn which will reduce its power consumption. when the bit changes state from low to high the internal counter value will be reset to zero, however when the bit changes from high to low , the internal counter will retain its residual value until the bit returns high again. if the ctmn is in the compare match output mode then the ctmn output pin will be reset to its initial condition, as specifed by the ctnoc bit, when the ctnon bit changes from low to high. bit 2~0 ctnrp2~ctnrp0 : ctmn ccrp 3-bit register, compared with the ctmn counter bit 9 ~ bit 7 000: 1024 ctmn clocks 001: 128 ctmn clocks 010: 256 ctmn clocks 011: 384 ctmn clocks 100: 512 ctmn clocks 101: 640 ctmn clocks 110: 768 ctmn clocks 111: 896 ctmn clocks these three bits are used to setup the value on the internal ccrp 3-bit register , which are then compared with the internal counter s highest three bits. the result of this comparison can be selected to clear the internal counter if the ctncclr bit is set to zero. setting the ctncclr bit to zero ensures that a compare match with the ccrp values will reset the internal counter . as the ccrp bits are only compared with the highest three counter bits, the compare values exist in 128 clock cycle multiples. clearing a ll t hree bi ts t o z ero i s i n e ffect a llowing t he c ounter t o ove rflow a t i ts maximum value.
rev. 1.40 1 ? 0 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?1 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ctmnc1 register bit 7 6 5 4 3 2 1 0 na ? e ctnm1 ctnm0 ctnio1 ctnio0 ctnoc ctnpol ctndpx ctncclr r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 ctnm1~ctnm0: select ctmn operating mode 00: compare match output mode 01: undefned 10: pwm mode 11: t imer/counter mode these bits s etup the required operating mode for the ctm n. t o ens ure reliable operation the ctmn should be switched of f before any changes are made to the ctnm1 a nd c tnm0 b its. i n t he t imer/counter mo de, t he c tmn o utput p in c ontrol will be disabled. bit 5~4 ctnio1~ctnio0 : select ctmn external pin (ctpn) function compare match output mode 00: no change 01: output low 10: output high 11: t oggle output pwm output mode 00: pwm output inactive state 01: pwm output active state 10: pwm output 11: undefned timer/counter mode unused these two bits are used to determin e how the ctmn output pin changes state when a certain condition is reached. the function that these bits select depends upon in which mode the ctmn is running. in the compare match output mode, the ctnio1 and ctnio0 bits determine how the ctmn o utput p in c hanges st ate wh en a c ompare m atch o ccurs f rom t he c omparator a. the ctmn output pin can be setup to switch high, switch low or to toggle its present state when a compare match occurs from the comparator a. when the bits are both zero, then no change will take place on the output. the initial value of the ctmn output pi n sho uld be se tup usi ng t he c tnoc bi t i n t he c tmnc1 re gister. not e t hat the output level requested by the ctnio1 and ctnio0 bits must be dif ferent from the initial value setup using the ctnoc bit otherwise no change will occur on the ctmn output pi n when a com pare match occurs. after the ctmn output pi n changes state, it can be reset to its initial level by changing the level of the ctnon bit from low to high. in the pwm mode, the ctnio1 and ctnio0 bits determine how the ctmn output pin changes state when a certain compare match condition occurs. the pwm output function i s m odified b y c hanging t hese t wo b its. i t i s n ecessary t o o nly c hange t he values of the ctnio1 and ctnio0 bits only after the ctmn has been switched of f. unpredictable pwm outputs will occur if the ctnio1 and ctnio0 bits are changed when the ctmn is running.
rev. 1.40 1?0 de?e??e? 1?? ?01? rev. 1.40 1 ? 1 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 3 ctnoc : ctpn output control compare match output mode 0: initial low 1: initial high pwm output mode 0: active low 1: active high this i s t he ou tput c ontrol bi t fo r t he ct mn o utput pi n. it s op eration de pends up on whether ct mn i s be ing used i n t he com pare ma tch output mode or i n t he pwm mode. it ha s no e ffect i f t he ct mn i s i n t he t imer/counter mode. in t he com pare match out put mode i t de termines t he l ogic l evel of t he ct mn out put pi n be fore a compare match occurs. in the pwm mode it determines if the pwm signal is active high or active low. bit 2 ctnpol: ctpn output polarity control 0: non-inverted 1: inverted this bit controls the pol arity of the ctpn out put pin. when the bit is set high the ctmn output pin will be inverted and not inverted when the bit is zero. it has no effect if the tm is in the t imer/counter mode. bit 1 ctndpx : ctmn pwm duty/period control 0: ccrp C period; ccra C duty 1: ccrp C duty; ccra C period this b it d etermines wh ich o f t he c cra a nd c crp r egisters a re u sed f or p eriod a nd duty control of the pwm waveform. bit 0 ctncclr : ctmn counter clear condition selection 0: ctmn comparator p match 1: ctmn comparator a match this bi t i s use d t o se lect t he m ethod whi ch c lears t he c ounter. re member t hat t he compact tm contains two comparators, comparator a and comparator p , either of which can be selected to clear the internal counter . w ith the ctncclr bi t set hi gh, the counter will be cleared when a compare match occurs from the comparator a. when the bit is low , the counter will be cleared when a compare match occurs from the comparator p or with a counter overfow . a counter overfow clearing method can only be implemented if the ccrp bits are all cleared to zero. the ctncclr bit is not used in the pwm mode.
rev. 1.40 1 ?? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?3 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver compact type tm operation modes the compact t ype tm can operate in one of three operating modes, compare match output mode, pwm mode or t imer/counter mode. the operating mode is selected using the ctnm1 and ctnm0 bits in the ctmnc1 register. compare match output mode to select this mode, bits ctnm1 and ctnm0 in the ctmnc1 register , should be set to "00" respectively. in this mode once the counter is enabled and running it can be cleared by three methods. these are a counter overfow , a compare match from comparator a and a compare match from c omparator p . w hen t he c tncclr b it i s l ow, t here a re t wo wa ys i n wh ich t he c ounter c an be cleared. one is when a compare match occurs from comparator p , the other is when the ccrp bits are all zero which allows the counter to overfow . here both ctmnaf and ctmnpf interrupt request fags for the comparator a and comparator p respectively, will both be generated. if the ctncclr bit in the ctmnc1 register is high then the counter will be cleared when a compare match occurs from com parator a. however , here onl y the ctmnaf interrupt request fag wil l be generated even if the value of the ccrp bits is less than that of the ccra registers. therefore when ctncclr is high no ctm npf interrupt request fag will be generated. if the ccra bits are all zero, the counter will overfow when its reaches its maximum 10-bit, 3ff hex, value, however here the ctmnaf interrupt request fag will not be generated. as the name of the mode suggests, after a comparison is made, the ctmn output pin will change state. the ctmn output pin condition however only changes state when a ctmnaf interrupt request fag is generated after a compare match occurs from comparat or a. the ctmnpf interrupt request fa g, g enerated f rom a c ompare m atch o ccurs f rom c omparator p , wi ll h ave n o e ffect o n the ctmn output pin. the way in which the ctmn output pin changes state are determined by the condition of the ctnio1 and ctnio0 bits in the ctmnc1 register . the ctmn output pin can be selected using the ctnio1 and ctnio0 bits to go high, to go low or to toggle from its present condition when a compare match occurs from comparator a. the initial condition of the ctmn output pin, which is setup after the ctnon bit changes from low to high, is setup using the ctnoc bit. note that if the ctnio1 and ctnio0 bits are zero then no pin change will take place.
rev. 1.40 1?? de?e??e? 1?? ?01? rev. 1.40 1 ? 3 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value 0x3ff ccrp ccra ctnon ctnpau ctnpol ccrp int. flag ctmnpf ccra int. flag ctmnaf ctmn o/p pin ti?e ccrp=0 ccrp > 0 counte? ove?flow ccrp > 0 counte? ?lea?ed ?y ccrp value pause resu?e stop counte? resta?t ctncclr = 0; ctnm [1:0] = 00 output pin set to initial level low if ctnoc=0 output toggle with ctmnaf flag note ctnio [1:0] = 10 a?tive high output sele?t he?e ctnio [1:0] = 11 toggle output sele?t output not affe?ted ?y ctmnaf flag. re?ains high until ?eset ?y ctnon ?it output pin reset to initial value output ?ont?olled ?y othe? pin-sha?ed fun?tion output inve?ts when ctnpol is high compare match output mode C ctncclr = 0 note: 1. w ith ctncclr=0, a comparator p match will clear the counter 2. the ctmn output pin controlled only by ctmnaf fag 3. the output pin is reset to its initial state by ctnon bit rising edge 4. n = 0 or 1
rev. 1.40 1 ? 4 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value 0x3ff ccrp ccra ctnon ctnpau ctnpol ctmn o/p pin ti?e ccra=0 ccra = 0 counte? ove?flow ccra > 0 counte? ?lea?ed ?y ccra value pause resu?e stop counte? resta?t ctncclr = 1; ctnm [1:0] = 00 output pin set to initial level low if ctnoc=0 output toggle with ctmnaf flag note ctnio [1:0] = 10 a?tive high output sele?t he?e ctnio [1:0] = 11 toggle output sele?t output not affe?ted ?y ctmnaf flag. re?ains high until ?eset ?y ctnon ?it output pin reset to initial value output ?ont?olled ?y othe? pin-sha?ed fun?tion output inve?ts when ctnpol is high ctmnpf not gene?ated no ctmnaf flag gene?ated on ccra ove?flow output does not ?hange ccra int. flag ctmnaf ccrp int. flag ctmnpf compare match output mode C ctncclr = 1 note: 1. w ith ctncclr=1, a comparator a match will clear the counter 2. the ctmn output pin is controlled only by ctmnaf fag 3. the ctmn output pin is reset to initial state by ctnon rising edge 4. the ctmnpf fags is not generated when ctncclr=1 5. n = 0 or 1
rev. 1.40 1?4 de?e??e? 1?? ?01? rev. 1.40 1 ?? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver timer/counter mode to se lect t his m ode, bi ts ct nm1 and ct nm0 i n t he ctmnc1 regi ster shoul d be se t t o 1 1 respectively. the t imer/counter mode operates in an identical way to the compare match output mode generating the same interrupt flags. the exception is that in the t imer/counter mode the ctmn output pin is not used. therefore the above description and t iming diagrams for the compare match output mode can be used to understand its function. as the ctmn output pin is not used in this mode, the pin can be used as a normal i/o pin or other pin-shared function. pwm output mode to select this mode, bits ctnm1 and ctnm0 in the ctmnc1 register should be set to 10 respectively. the pwm function within the ctmn is useful for applications which require functions such as motor control, heating control, illumination control etc. by providing a signal of fixed frequency but of varying duty cycle on the ctmn output pin, a square wave ac waveform can be generated with varying equivalent dc rms values. as both the period and duty cycle of the pwm waveform can be controlled, the choice of generated waveform is extremely f exible. in the p wm mode, the ctncclr bit has no ef fect on the p wm operation. bot h of t he ccra a nd ccrp re gisters a re use d t o ge nerate t he pw m wave form, one register is used to clear the internal counter and thus control the pwm waveform frequency , while the other one is used to control the duty cycle. which register is used to control either frequency or duty cycle is determined using the ctndpx bit in the ctmnc1 register . the pwm waveform frequency and duty cycle can therefore be controlled by the values in the ccra and ccrp registers. an interrupt fag, one for each of the ccra and ccrp , will be generated when a compare match occurs from either comparator a or comparator p . the ctnoc bit in the ctmnc1 register is used to select the required polarity of the pwm waveform while the tw o ctnio1 and ctnio0 bits are used to enable the pwm output or to force the tm output pin to a fixed high or low level. the ctnpol bit is used to reverse the polarity of the pwm output waveform. ? 10-bit ctmn, pwm mode, edge-aligned mode, ctndpx=0 ccrp 001b 010b 011b 100b 101b 110b 111b 000b pe ? iod 1 ? 8 ??? 384 ? 1 ? ? 40 7 ? 8 89 ? 10 ? 4 duty ccra if f sys =16mhz, ctmn clock source is f sys /4, ccrp=2 and ccra=128, the ctmn pwm output frequency=(f sys /4)/256=f sys /1024=15.625khz, duty=128/256=50%. if the duty value defned by the ccra register is equal to or greater than the period value, then the pwm output duty is 100%. ? 10-bit ctmn, pwm mode, edge-aligned mode, ctndpx=1 ccrp 001b 010b 011b 100b 101b 110b 111b 000b pe ? iod ccra duty 1 ? 8 ??? 384 ? 1 ? ? 40 7 ? 8 89 ? 10 ? 4 the pwm output period is determi ned by the ccra register value together with the ctmn clock while the pwm duty cycle is defned by the ccrp register value.
rev. 1.40 1 ?? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?7 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value ccrp ccra ctnon ctnpau ctnpol ctmn o/p pin (ctnoc=1) ti?e counte? ?lea?ed ?y ccrp pause resu?e counte? stop if ctnon ?it low counte? reset when ctnon ?etu?ns high ctndpx = 0; ctnm [1:0] = 10 pwm duty cy?le set ?y ccra pwm ?esu?es ope?ation output ?ont?olled ?y othe? pin-sha?ed fun?tion output inve?ts when ctnpol = 1 pwm pe?iod set ?y ccrp ctmn o/p pin (ctnoc=0) ccra int. flag ctmnaf ccrp int. flag ctmnpf pwm output mode C ctndpx = 0 note: 1. here ctndpx=0 C counter cleared by ccrp 2. a counter clear sets pwm period 3. the internal pwm function continues even when ctnio [1:0]=00 or 01 4. the ctncclr bit has no infuence on pwm operation 5. n = 0 or 1
rev. 1.40 1?? de?e??e? 1?? ?01? rev. 1.40 1 ? 7 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value ccrp ccra ctnon ctnpau ctnpol ccrp int. flag ctmnpf ccra int. flag ctmnaf ctmn o/p pin (ctnoc=1) ti?e counte? ?lea?ed ?y ccra pause resu?e counte? stop if ctnon ?it low counte? reset when ctnon ?etu?ns high ctndpx = 1; ctnm [1:0] = 10 pwm duty cy?le set ?y ccrp pwm ?esu?es ope?ation output ?ont?olled ?y othe? pin-sha?ed fun?tion output inve?ts when ctnpol = 1 pwm pe?iod set ?y ccra ctmn o/p pin (ctnoc=0) pwm output mode C ctndpx = 1 note: 1. here ctndpx = 1 C counter cleared by ccra 2. a counter clear sets pwm period 3. the internal pwm function continues even when ctnio [1:0] = 00 or 01 4. the ctncclr bit has no infuence on pwm operation 5. n = 0 or 1
rev. 1.40 1 ? 8 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?9 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver standard type tm C stm the standard t ype tm contains fve operating modes, which are compare match output, t imer/ event counter , capture input, single pulse output and pwm output modes. the standard tm can also be controlled with two external input pins and can drive two external output pin. device stm core stm input pin stm output pin bs ?? f340 bs ?? f3 ? 0 bs ?? f3 ? 0 bs ?? f370 1 ? - ? it stm stck ? stpi stp ? stpb f sys f sys /4 f h / ?4 f h / 1? f sub stck 000 001 010 011 100 101 110 111 stck ?~ stck 0 1?- ?it count - up counte? 8- ?it co?pa?ato? p ccrp ?8~? 1? ?0~? 1? 1? - ?it co?pa?ato? a ston stpau co?pa?ato? a mat?h co?pa?ato? p mat?h counte? clea? 0 1 output cont?ol pola?ity cont?ol pin cont?ol stp stoc stm 1 ? stm 0 stio 1 ? stio 0 stmaf inte??upt stmpf inte??upt stpol pxsn ccra stcclr edge dete?to? stpi stio 1 ? stio 0 f sub stpb standard type tm block diagram standard tm operation the size of standard tm is 16-bit wide and its core is a 16-bit count-up counter which is driven by a user selectable internal or externa l clock source. there are also two internal comparators with the names, comparato r a and comparator p . these comparators will compare the value in the counter with ccrp and ccra registers. the ccrp comparator is 8-bit wide whose value is compared the with highest 8 bits in the counter while the ccra is the sixteen bits and therefore compares all counter bits. the onl y way of changing the value of the 16-bit counte r using the appl ication program , is to clear t he c ounter b y c hanging t he st on b it f rom l ow t o h igh. t he c ounter wi ll a lso b e c leared automatically by a counter overfow or a compare match with one of its associated comparators. when these conditions occur , a stm interrupt signal will also usually be generated. the standard type tm can operate in a number of dif ferent operational modes, can be driven by dif ferent clock sources including an input pin and can also control an output pin. all operating setup conditions are selected using relevant internal registers.
rev. 1.40 1?8 de?e??e? 1?? ?01? rev. 1.40 1 ? 9 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver standard type tm register description overall operation of the standard tm is controlled using a series of registers. a read only register pair e xists t o st ore t he i nternal c ounter 16 -bit va lue, whi le a re ad/write re gister pa ir e xists t o st ore the internal 16-bit ccra value. the stmrp register is used to store the 8-bit ccrp value. the remaining two registers are control registers which setup the different operating and control modes. register name bit 7 6 5 4 3 2 1 0 stmc0 stpau stck ? stck1 stck0 ston stmc1 stm1 stm0 stio1 stio0 stoc stpol stdpx stcclr stmdl d7 d ? d ? d4 d3 d ? d1 d0 stmdh d1 ? d14 d13 d1 ? d11 d10 d9 d8 stmal d7 d ? d ? d4 d3 d ? d1 d0 stmah d1 ? d14 d13 d1 ? d11 d10 d9 d8 stmrp strp7 strp ? strp ? strp4 strp3 strp ? strp1 strp0 16-bit standard tm registers list stmdl register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r r r r r r r r por 0 0 0 0 0 0 0 0 bit 7~0 stm counter low byte register bit 7 ~ bit 0 stm 16-bit counter bit 7 ~ bit 0 stmdh register bit 7 6 5 4 3 2 1 0 na ? e d1 ? d14 d13 d1 ? d11 d10 d9 d8 r/w r r r r r r r r por 0 0 0 0 0 0 0 0 bit 7~0 stm counter high byte register bit 7 ~ bit 0 stm 16-bit counter bit 15 ~ bit 8 stmal register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 stm ccra low byte register bit 7 ~ bit 0 stm 16-bit ccra bit 7 ~ bit 0 stmah register bit 7 6 5 4 3 2 1 0 na ? e d1 ? d14 d13 d1 ? d11 d10 d9 d8 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 stm ccra high byte register bit 7 ~ bit 0 stm 16-bit ccra bit 15 ~ bit 8
rev. 1.40 130 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 131 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver stmc0 register bit 7 6 5 4 3 2 1 0 na ? e stpau stck ? stck1 stck0 ston r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 bit 7 stpau : stm counter pause control 0: run 1: pause the c ounter c an be pa used by se tting t his bi t hi gh. cl earing t he bi t t o z ero re stores normal c ounter ope ration. w hen i n a pa use c ondition t he st m wi ll rem ain powe red up a nd c ontinue t o c onsume po wer. t he c ounter wi ll re tain i ts re sidual va lue whe n this bit changes from low to high and res ume counting from this value w hen the bit changes to a low value again. bit 6~4 stck2~stck0 : select stm counter clock 000: f sys /4 001: f sys 010: f h /16 011: f h /64 100: f sub 101: f sub 110: stck rising edge clock 111: stck falling edge clock these three bits are used to select the clock source for the stm. the external pin clock source can be chosen to be active on the rising or falling edge. the cloc k source f sys is the system clock, while f h and f sub are other internal clocks, the detai ls of which can be found in the oscillator section. bit 3 ston : stm counter on/off control 0: off 1: on this bit controls the overall on/of f function of the stm. setting the bit high enables the counter to run while clearing the bit disables the stm. clearing this bit to zero will stop the counter from counting and turn of f the stm which will reduce its power consumption. when the bit changes state from low to high the internal counter value will be reset to zero, however when the bit changes from high to low , the internal counter will retain its residual value until the bit returns high again. if the stm is in the compare match output mode then the stm output pin will be reset to its initial condition, as specifed by the stoc bit, when the ston bit changes from low to high. bit 2~0 unimplemented, read as "0" stmc1 register bit 7 6 5 4 3 2 1 0 na ? e stm1 stm0 stio1 stio0 stoc stpol stdpx stcclr r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 stm1~stm0 : select stm operating mode 00: compare match output mode 01: capture input mode 10: pwm mode or single pulse output mode 11: t imer/counter mode these bits setup the required operating mode for the stm. t o ensure reliable operation the stm should be switched of f before any changes are made to the stm1 and stm0 bits. in the t imer/counter mode, the stm output pin control will be disabled.
rev. 1.40 130 de?e??e? 1?? ?01? rev. 1.40 131 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 5~4 stio1~stio0 : select stm external pin (stp or stpi) function compare match output mode 00: no change 01: output low 10: output high 11: t oggle output pwm output mode/single pulse output mode 00: pwm output inactive state 01: pwm output active state 10: pwm output 11: single pulse output capture input mode 00: input capture at rising edge of stpi 01: input capture at falling edge of stpi 10: input capture at rising/falling edge of stpi 11: input capture disabled timer/counter mode unused these two bits are used to determine how the stm output pin changes state when a certain condition is reached. the function that these bits select depends upon in which mode the stm is running. in t he com pare mat ch out put mode , t he st io1 a nd st io0 bi ts de termine how t he stm output pin changes state when a compare match occurs from the comparator a. the tm output pin can be setup to switch high, switch low or to toggle its present state when a compare match occurs from the comparator a. when the bits are both zero, then no change will take place on the output. the initial value of the stm output pin sh ould b e se tup u sing t he st oc b it i n t he st mc1 r egister. no te t hat t he o utput level requested by the stio1 and stio0 bits must be dif ferent from the initial value setup using the st oc bit otherwise no change will occur on the stm output pin when a compare match occurs. after the stm output pin changes state, it can be reset to its initial level by changing the level of the ston bit from low to high. in the pwm mode, the stio1 and stio0 bits determine how the stm output pin changes state when a certain compare match condition occurs. the pwm output function i s m odified b y c hanging t hese t wo b its. i t i s n ecessary t o o nly c hange t he values of t he st io1 a nd st io0 bi ts onl y a fter t he st m ha s be en swi tched of f. unpredictable pw m out puts wi ll oc cur i f t he st io1 a nd st io0 bi ts a re c hanged when the stm is running. bit 3 stoc : stm stp output control compare match output mode 0: initial low 1: initial high pwm output mode/single pulse output mode 0: active low 1: active high this is the output control bit for the stm output pin. its operation depends upon whether st m i s b eing u sed i n t he c ompare ma tch ou tput mo de o r i n t he pw m mode/single pulse output mode. it has no ef fect if the stm is in the t imer/counter mode. in the compare match output mode it determines the logic level of the stm output pin before a compare match occurs. in the pwm mode/single pulse output mode it determines if the pwm signal is active high or active low.
rev. 1.40 13 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 133 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 2 stpol : stm stp output polarity control 0: non-inverted 1: inverted this bit controls the polarity of the stp output pin. when the bit is set high the stm output pin will be inverted and not inverted when the bit is zero. it has no ef fect if the stm is in the t imer/counter mode. bit 1 stdpx : stm pwm duty/period control 0: ccrp C period; ccra C duty 1: ccrp C duty; ccra C period this b it d etermines wh ich o f t he c cra a nd c crp r egisters a re u sed f or p eriod a nd duty control of the pwm waveform. bit 0 stcclr : stm counter clear condition selection 0: comparator p match 1: comparator a match this bi t i s use d t o se lect t he m ethod whi ch c lears t he c ounter. re member t hat t he standard tm contains two comparators, comparator a and comparator p , either of which can be selected to clear the internal counter . w ith the stcclr bit set high, the counter will be cleared when a compare match occurs from the comparator a. when the bit is low , the counter will be cleared when a compare match occurs from the comparator p or with a counter overfow . a counter overfow clearing method can only be implemented if the ccrp bits are all cleared to zero. the stcclr bit is not used in the pwm output, single pulse output or capture input mode. stmrp register bit 7 6 5 4 3 2 1 0 na ? e strp7 strp ? strp ? strp4 strp3 strp ? strp1 strp0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 strp7~strp0 : stm ccrp 8-bit register, compared with the stm counter bit 15~bit 8 comparator p match period = 0: 65536 stm clocks 1~255: (1~255) 256 stm clocks these eight bits are used to setup the value on the internal ccrp 8-bit register , which are then compared with the internal counter s highest eight bits. the result of this comparison ca n be se lected to cl ear the int ernal counte r if t he st cclr bit is se t t o zero. se tting the st cclr bit to ze ro ensures tha t a compa re ma tch wi th the ccrp values will reset the internal counter . as the ccrp bits are only compared with the highest eight counter bits, the compare values exist in 256 clock cycle multiples. clearing a ll e ight bi ts t o z ero i s i n e ffect a llowing t he c ounter t o ove rflow a t i ts maximum value.
rev. 1.40 13? de?e??e? 1?? ?01? rev. 1.40 133 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver standard type tm operation modes the standard t ype tm can operate in one of fve operating modes, compare match output mode, pwm output mode, single pulse output mode, capture input mode or t imer/counter mode. the operating mode is selected using the stm1 and stm0 bits in the stmc1 register. compare match output mode to select this mode, bits stm1 and stm0 in the stmc1 register , should be set to 00 respectively . in this mode once the counter is enabled and running it can be cleared by three methods. these are a counter overfow , a compare matc h from comparator a and a compare match from comparator p . when the stcclr bit is low , there are two ways in which the counter can be cleared. one is when a compare match from comparator p , the other is when the ccrp bits are all zero which allows the counter t o ov erfow. he re bo th st maf a nd st mpf i nterrupt re quest fa gs fo r co mparator a a nd comparator p respectively, will both be generated. if the stcclr bit in the stmc1 register is high then the counter will be cleared when a compare match oc curs from com parator a. howe ver, he re onl y t he st maf i nterrupt re quest fa g wi ll be generated even if the value of the ccrp bits is less than that of the ccra registers. therefore when stcclr is high no stmpf interru pt request fag will be generated. in the compare match output mode, the ccra can not be set to "0". as the name of the mode suggests, after a comparison is made, the stm output pin, will change state. the stm output pin condition however only changes state when a stmaf interrupt request fag is generated after a compare match occurs from comparator a . the s tmpf interrupt reques t fag, g enerated fr om a c ompare m atch o ccurs fr om c omparator p , wi ll h ave n o e ffect o n t he st m output pin. the way in which the stm output pin changes state are determined by the condition of the stio1 and stio0 bits in the stmc1 register . the stm output pin can be selected using the stio1 and stio0 bits to go high, to go low or to toggle from its present condition when a compare match occurs from comparator a. the initial condition of the stm output pin, which is setup after the st on bit changes from low to high, is setup using the st oc bit. note that if the stio1 and stio0 bits are zero then no pin change will take place.
rev. 1.40 134 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 13? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value 0xffff ccrp ccra ston stpau stpol ccrp int. flag stmpf ccra int. flag stmaf stm o/p pin ti?e ccrp=0 ccrp > 0 counte? ove?flow ccrp > 0 counte? ?lea?ed ?y ccrp value pause resu?e stop counte? resta?t stcclr = 0; stm [1:0] = 00 output pin set to initial level low if stoc=0 output toggle with stmaf flag note stio [1:0] = 10 a?tive high output sele?t he?e stio [1:0] = 11 toggle output sele?t output not affe?ted ?y stmaf flag. re?ains high until ?eset ?y ston ?it output pin reset to initial value output ?ont?olled ?y othe? pin-sha?ed fun?tion output inve?ts when stpol is high compare match output mode C stcclr = 0 note: 1. w ith stcclr=0 a comparator p match will clear the counter 2. the stm output pin is controlled only by the stmaf fag 3. the output pin is reset to itsinitial state by a ston bit rising edge
rev. 1.40 134 de?e??e? 1?? ?01? rev. 1.40 13 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value 0xffff ccrp ccra ston stpau stpol ccrp int. flag stmpf ccra int. flag stmaf stm o/p pin ti?e ccra=0 ccra = 0 counte? ove?flow ccra > 0 counte? ?lea?ed ?y ccra value pause resu?e stop counte? resta?t stcclr = 1; stm [1:0] = 00 output pin set to initial level low if stoc=0 output toggle with stmaf flag note stio [1:0] = 10 a?tive high output sele?t he?e stio [1:0] = 11 toggle output sele?t output not affe?ted ?y stmaf flag. re?ains high until ?eset ?y ston ?it output pin reset to initial value output ?ont?olled ?y othe? pin-sha?ed fun?tion output inve?ts when stpol is high stmpf not gene?ated no stmaf flag gene?ated on ccra ove?flow output does not ?hange compare match output mode C stcclr = 1 note: 1. w ith stcclr=1 a comparator a match will clear the counter 2. the stm output pin is controlled only by the stmaf fag 3. the output pin is reset to its initial state by a ston bit rising edge 4. a stmpf fag is not generated when stcclr=1
rev. 1.40 13 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 137 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver timer/counter mode to select this mode, bits stm1 and stm0 in the stmc1 register should be set to 1 1 respectively . the t imer/counter m ode operates in an identical w ay to the compare m atch o utput m ode generating the s ame interrupt flags . the exception is that in the t imer/counter m ode the s tm output pin is not used. therefore the above description and t iming diagrams for the compare match out put mod e c an be use d t o un derstand i ts fu nction. as t he st m ou tput pi n i s no t use d i n this mode, the pin can be used as a normal i/o pin or other pin-shared function. pwm output mode to select this mode, bits stm1 and stm0 in the stmc1 register should be set to 10 respectively and als o the stio 1 and stio 0 bits should be set to 10 res pectively. the pwm function w ithin the stm is useful for applications which require functions such as motor control, heating control, illumination control etc. by providing a signal of fxed frequency but of varying duty cycle on the stm output pin, a square wave ac waveform can be generated with varying equivalent dc rms values. as both the period and duty cycle of the pwm waveform can be controlled, the choice of generated waveform is extre mely fl exible. in the pwm mode, the stcclr bi t ha s no ef fect as the pwm period. both of the ccra and ccrp registers are used to generate the pwm waveform, one register is used to clear the internal counter and thus control the pwm waveform frequency , while the other one is used to control the duty cycle. which register is used to control either frequency or duty cycle is determined using the stdpx bit in the stmc1 register . the pwm waveform frequency and duty cycle can therefore be controlled by the values in the ccra and ccrp registers. an interrupt fag, one for each of the ccra and ccrp , will be generated when a compare match occurs from either comparator a or comparator p . the st oc bit in the stmc1 register is used to select the required polarity of the pwm waveform while the two stio1 and stio0 bits are used to enable the pwm output or to force the stm output pin to a fxed high or low level. the stpol bit is used to reverse the polarity of the pwm output waveform. ? 16-bit stm, pwm mode, edge-aligned mode, stdpx=0 ccrp 1~255 0 pe ? iod ccrpx ??? ??? 3 ? duty ccra if f sys =16mhz, stm clock source is f sys /4, ccrp=2 and ccra=128, the stm pwm output frequency=(f sys /4)/(2 256)=f sys /2048=7.8125khz, duty=128/(2 256)=25%. if the duty value defned by the ccra register is equal to or greater than the period value, then the pwm output duty is 100%. ? 16-bit stm, pwm mode, edge-aligned mode, stdpx=1 ccrp 1~255 0 pe ? iod ccra duty ccrpx ??? ??? 3 ? the pw m o utput p eriod i s d etermined b y t he c cra r egister v alue t ogether wi th t he t m c lock while t he pw m d uty c ycle i s d efned b y t he c crp r egister v alue e xcept wh en t he c crp v alue i s equal to 0.
rev. 1.40 13? de?e??e? 1?? ?01? rev. 1.40 137 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value ccrp ccra ston stpau stpol ccrp int. flag stmpf ccra int. flag stmaf stm o/p pin (stoc=1) ti?e counte? ?lea?ed ?y ccrp pause resu?e counte? stop if ston ?it low counte? reset when ston ?etu?ns high stdpx = 0; stm [1:0] = 10 pwm duty cy?le set ?y ccra pwm ?esu?es ope?ation output ?ont?olled ?y othe? pin-sha?ed fun?tion output inve?ts when stpol = 1 pwm pe?iod set ?y ccrp stm o/p pin (stoc=0) pwm output mode C stdpx = 0 note: 1. here stdpx=0 C counter cleared by ccrp 2. a counter clear sets the pwm period 3. the internal pwm function continues running even when stio [1:0] = 00 or 01 4. the stcclr bit has no infuence on pwm operation
rev. 1.40 138 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 139 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value ccrp ccra ston stpau stpol ccrp int. flag stmpf ccra int. flag stmaf stm o/p pin (stoc=1) ti?e counte? ?lea?ed ?y ccra pause resu?e counte? stop if ston ?it low counte? reset when ston ?etu?ns high stdpx = 1; stm [1:0] = 10 pwm duty cy?le set ?y ccrp pwm ?esu?es ope?ation output ?ont?olled ?y othe? pin-sha?ed fun?tion output inve?ts when stpol = 1 pwm pe?iod set ?y ccra stm o/p pin (stoc=0) pwm output mode C stdpx = 1 note: 1. here stdpx=1 C counter cleared by ccra 2. a counter clear sets the pwm period 3. the internal pwm function continues even when stio [1:0] = 00 or 01 4. the stcclr bit has no infuence on pwm operation
rev. 1.40 138 de?e??e? 1?? ?01? rev. 1.40 139 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver single pulse output mode to select this mode, bits stm1 and stm0 in the stmc1 register should be set to 10 respectively and also the stio1 and stio0 bits should be set to 1 1 respectively . the single pulse output mode, as the name suggests, will generate a single shot pulse on the stm output pin. the trigger for the pulse output lead ing edge is a low to high transition of the st on bit, which can be i mplemented using t he a pplication progra m. however i n t he singl e pulse mode, t he st on bi t can also be made to automatically change from low to high using the external stck pin, which will in turn initiate the single pulse output. when the st on bit transitions to a high level, the counter will start running and the pulse leading edge will be generated. the st on bit should remain high when the pulse is in its active state. the generated pulse trailing edge will be generated when the ston bit is cleared to zero, which can be implemented using the application program or when a compare match occurs from comparator a. however a compare match from comparator a will also automatically clear the st on bit and thus generate the single pulse output trailing edge. in this way the ccra value can be used to control the pulse width. a compare match from comparator a will also generate a stm interrupt. the counter can only be reset back to zero when the st on bit changes from low to high when the counter restarts. in the single pulse mode ccrp is not used. the stcclr and stdpx bits are not used in this mode. ston ?it 0 1 s/ w co??and set ? ston ? o? stck pin t?ansition ston ?it 1 0 ccra t?ailing edge s/ w co??and clr ? ston ? o? ccra co?pa?e mat?h stp output pin pulse width = ccra value ccra leading edge single pulse generation
rev. 1.40 140 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 141 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value ccrp ccra ston stpau stpol ccrp int. flag stmpf ccra int. flag stmaf stm o/p pin ( stoc=1 ) ti?e counte? stopped ?y ccra pause resu?e counte? stops ?y softwa?e counte? reset when ston ?etu?ns high stm [1:0] = 10 ; stio [1:0] = 11 pulse width set ?y ccra output inve?ts when stpol = 1 no ccrp inte??upts gene?ated stm o/p pin ( stoc=0 ) stck pin softwa?e t?igge? clea?ed ?y ccra ?at?h stck pin t?igge? auto. set ?y stck pin softwa?e t?igge? softwa?e clea? softwa?e t?igge? softwa?e t?igge? single pulse mode note: 1. counter stopped by ccra 2. ccrp is not used 3. the pulse triggered by the stck pin or by setting the ston bit high 4. a stck pin active edge will automatically set the ston bit high. 5. in the single pulse mode, stio [1:0] must be set to "11" and can not be changed.
rev. 1.40 140 de?e??e? 1?? ?01? rev. 1.40 141 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver capture input mode to select this mode bits stm1 and stm0 in the stmc1 register should be set to 01 respectively . this mode enables external s ignals to capture and s tore the pres ent value of the internal counter and c an t herefore be use d fo r a pplications suc h a s pu lse wi dth m easurements. t he e xternal si gnal is suppl ied on t he st pi pi n, whose a ctive e dge c an be a ri sing e dge, a fa lling e dge or bot h ri sing and falling edges; the active edge transition type is selected using the stio1 and stio0 bits in the stmc1 register . the counter is started when the st on bit changes from low to high which is initiated using the application program. when the required edge transition appears on the stpi pin the present value in the counter will be latched into the ccra registers and a stm interrupt generated. irrespective of what events occur on the stpi pin the counter will continue to free run until the st on bit changes from high to low . when a ccrp compare match occurs the counter will reset back to zero; in this way the ccrp value c an be use d t o c ontrol t he m aximum c ounter va lue. w hen a ccrp c ompare m atch oc curs from comparat or p , a stm interrupt will also be generated. counting the number of overfl ow interrupt signals from the ccrp can be a useful method in measuring long pulse widths. the stio1 and stio0 bits can select the active trigger edge on the stpi pin to be a rising edge, falling edge or both edge types. if the stio1 and stio0 bits are both set high, then no capture operation will take place irrespective of what happens on the stpi pin, however it must be noted that the counter will continue to run. the stcclr and stdpx bits are not used in this mode.
rev. 1.40 14 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 143 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value yy ccrp ston stpau ccrp int. flag stmpf ccra int. flag stmaf ccra value ti?e counte? ?lea?ed ?y ccrp pause resu?e counte? reset stm [1:0] = 01 stm ?aptu?e pin stpi xx counte? stop stio [1:0] value xx yy xx yy a?tive edge a?tive edge a?tive edge 00 C rising edge 01 C falling edge 10 C both edges 11 C disa?le captu?e capture input mode note: 1. stm [1:0] = 01 and active edge set by the stio [1:0] bits 2. a stm capture input pin active edge transfers the counter value to ccra 3. stcclr bit not used 4. no output function -- stoc and stpol bits are not used 5. ccrp determines the counter value and the counter has a maximum count value when ccrp is equal to zero.
rev. 1.40 14? de?e??e? 1?? ?01? rev. 1.40 143 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver periodic type tm C ptm the pe riodic t ype t m c ontains fv e o perating m odes, wh ich a re c ompare ma tch ou tput, t imer/ event counter , capture input, single pulse output and pwm output modes. the periodic tm can also be controlled with two external input pins and can drive two external output pin. device ptm core ptm input pin ptm output pin bs ?? f340 bs ?? f3 ? 0 bs ?? f3 ? 0 bs ?? f370 10- ? it ptm ptck ? ptpi ptp ? ptpb f sys f sys /4 f h / ?4 f h / 1? f sub ptck 000 001 010 011 100 101 110 111 ptck ?~ ptck 0 10 - ?it count - up counte? 10- ?it co?pa?ato? p ccrp ?0~?9 ?0~?9 10 - ?it co?pa?ato? a pton ptpau co?pa?ato? a mat?h co?pa?ato? p mat?h counte? clea? 0 1 output cont?ol pola?ity cont?ol pin cont?ol ptp ptoc ptm 1 ? ptm 0 ptio 1 ? ptio 0 ptmaf inte??upt ptmpf inte??upt ptpol pxsn ccra ptcclr edge dete?to? ptpi ptio 1 ? ptio 0 f sub 1 0 pin cont?ol ifs ptcapts ptpb periodic type tm block diagram periodic tm operation the size of periodic tm is 10-bit wide and its core is a 10-bit count-up counter which is driven by a user selectable internal or externa l clock source. there are also two internal comparators with the names, comparato r a and comparator p . these comparators will compare the value in the counter with ccrp and ccra registers. the ccrp and ccra comparators are 10-bit wide whose value is respectively compared with all counter bits. the onl y wa y of c hanging t he va lue of t he 10-bi t c ounter usi ng t he a pplication program i s t o clear t he c ounter b y c hanging t he pt on b it f rom l ow t o h igh. t he c ounter wi ll a lso b e c leared automatically by a counter overfow or a compare match with one of its associated comparators. when t hese c onditions occ ur, a pt m i nterrupt si gnal wi ll a lso usua lly be ge nerated. t he pe riodic type tm can operate in a number of dif ferent operational modes, can be driven by dif ferent clock sources including an input pin and can also control the output pins. all operating setup conditions are selected using relevant internal registers.
rev. 1.40 144 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 14? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver periodic type tm register description overall operation of the periodic tm is controlled using a series of registers. a read only register pair exists to store the internal counter 10-bit value, while two read/write register pairs exist to store the internal 10-bit ccra and ccrp value. the remaining two registers are control registers which setup the different operating and control modes. register name bit 7 6 5 4 3 2 1 0 ptmc0 ptpau ptck ? ptck1 ptck0 pton ptmc1 ptm1 ptm0 ptio1 ptio0 ptoc ptpol ptcapts ptcclr ptmdl d7 d ? d ? d4 d3 d ? d1 d0 ptmdh d9 d8 ptmal d7 d ? d ? d4 d3 d ? d1 d0 ptmah d9 d8 ptmrpl ptrp7 ptrp ? ptrp ? ptrp4 ptrp3 ptrp ? ptrp1 ptrp0 ptmrph ptrp9 ptrp8 periodic tm registers list ptmdl register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r r r r r r r r por 0 0 0 0 0 0 0 0 bit 7~0 ptm counter low byte register bit 7 ~ bit 0 ptm 10-bit counter bit 7 ~ bit 0 ptmdh register bit 7 6 5 4 3 2 1 0 na ? e d9 d8 r/w r r por 0 0 bit 7~2 unimplemented, read as "0" bit 1~0 ptm counter high byte register bit 1 ~ bit 0 ptm 10-bit counter bit 9 ~ bit 8 ptmal register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 ptm ccra low byte register bit 7 ~ bit 0 ptm 10-bit ccra bit 7 ~ bit 0
rev. 1.40 144 de?e??e? 1?? ?01? rev. 1.40 14 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ptmah register bit 7 6 5 4 3 2 1 0 na ? e d9 d8 r/w r/w r/w por 0 0 bit 7~2 unimplemented, read as "0" bit 1~0 ptm ccra high byte register bit 1 ~ bit 0 ptm 10-bit ccra bit 9 ~ bit 8 ptmrpl register bit 7 6 5 4 3 2 1 0 na ? e ptrp7 ptrp ? ptrp ? ptrp4 ptrp3 ptrp ? ptrp1 ptrp0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 ptrp7~ptrp0: ptm ccrp low byte register bit 7 ~ bit 0 ptm 10-bit ccrp bit 7 ~ bit 0 ptmrph register bit 7 6 5 4 3 2 1 0 na ? e ptrp9 ptrp8 r/w r/w r/w por 0 0 bit 7~2 unimplemented, read as "0" bit 1~0 ptrp9~ptrp8: ptm ccrp high byte register bit 1 ~ bit 0 ptm 10-bit ccrp bit 9 ~ bit 8 ptmc0 register bit 7 6 5 4 3 2 1 0 na ? e ptpau ptck ? ptck1 ptck0 pton r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 bit 7 ptpau : ptm counter pause control 0: run 1: pause the c ounter c an be pa used by se tting t his bi t hi gh. cl earing t he bi t t o z ero re stores normal c ounter ope ration. w hen i n a pa use c ondition t he pt m wi ll rem ain powe red up a nd c ontinue t o c onsume po wer. t he c ounter wi ll re tain i ts re sidual va lue whe n this bit changes from low to high and res ume counting from this value w hen the bit changes to a low value again. bit 6~4 ptck2~ptck0 : select ptm counter clock 000: f sys /4 001: f sys 010: f h /16 011: f h /64 100: f sub 101: f sub 110: ptck rising edge clock 111: ptck falling edge clock these three bits are used to select the clock source for the ptm. the external pin clock source can be chosen to be active on the rising or falling edge. the cloc k source f sys is the system clock, while f h and f sub are other internal clocks, the detai ls of which can be found in the oscillator section.
rev. 1.40 14 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 147 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 3 pton : ptm counter on/off control 0: off 1: on this bit controls the overall on/of f function of the ptm. setting the bit high enables the counter to run while clearing the bit disables the ptm. clearing this bit to zero will stop the counter from counting and turn of f the ptm which will reduce its power consumption. when the bit changes state from low to high the internal counter value will be reset to zero, however when the bit changes from high to low , the internal counter will retain its residual value until the bit returns high again. if the ptm is in the compare match output mode then the ptm output pin will be reset to its initial condition, as specifed by the ptoc bit, when the pton bit changes from low to high. bit 2~0 unimplemented, read as "0" ptmc1 register bit 7 6 5 4 3 2 1 0 na ? e ptm1 ptm0 ptio1 ptio0 ptoc ptpol ptcapts ptcclr r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 ptm1~ptm0 : select ptm operating mode 00: compare match output mode 01: capture input mode 10: pwm mode or single pulse output mode 11: t imer/counter mode these bits setup the required operating mode for the ptm. t o ensure reliable operation the ptm should be switched of f before any changes are made to the ptm1 and ptm0 bits. in the t imer/counter mode, the ptm output pin control will be disabled. bit 5~4 ptio1~ptio0 : select ptm external pin ptp or ptpi function compare match output mode 00: no change 01: output low 10: output high 11: t oggle output pwm output mode/single pulse output mode 00: pwm output inactive state 01: pwm output active state 10: pwm output 11: single pulse output capture input mode 00: input capture at rising edge of ptpi or ptck 01: input capture at falling edge of ptpi or ptck 10: input capture at rising/falling edge of ptpi or ptck 11: input capture disabled timer/counter mode unused these two bits are used to determine how the ptm output pin changes state when a certain condition is reached. the function that these bits select depends upon in which mode the ptm is running.
rev. 1.40 14? de?e??e? 1?? ?01? rev. 1.40 147 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver in t he com pare mat ch out put mode , t he pt io1 a nd pt io0 bi ts de termine how t he ptm output pin changes state when a compare match occurs from the comparator a. the pt m out put pi n c an be se tup t o swi tch hi gh, swi tch l ow or t o t oggle i ts pre sent state when a compare match occurs from the comparator a. when the bits are both zero, then no change will take place on the output. the initial value of the ptm output pin sh ould b e se tup u sing t he pt oc b it i n t he pt mc1 r egister. no te t hat t he o utput level requested by the ptio1 and ptio0 bits must be dif ferent from the initial value setup using the pt oc bit otherwise no change will occur on the ptm output pin when a compare match occurs. after the ptm output pin changes state, it can be reset to its initial level by changing the level of the pton bit from low to high. in the pwm mode, the ptio1 and ptio0 bits determine how the tm output pin changes state when a certain compare match condition occurs. the ptm output function is modifed by changing these two bits. it is necessary to only change the values of the ptio1 and ptio0 bits only after the ptm has been switched of f. unpredictable pwm outputs will occur if the ptio1 and ptio0 bits are changed when the ptm is running. bit 3 ptoc : ptm ptp output control compare match output mode 0: initial low 1: initial high pwm output mode/single pulse output mode 0: active low 1: active high this is the output control bit for the ptm output pin. its operation depends upon whether pt m i s b eing u sed i n t he c ompare ma tch ou tput mo de o r i n t he pw m mode/single pulse output mode. it has no ef fect if the ptm is in the t imer/counter mode. in the compare match output mode it determines the logic level of the ptm output pin before a compare match occurs. in the pwm mode/single pulse output mode it determines if the pwm signal is active high or active low. bit 2 ptpol : ptm ptp output polarity control 0: non-inverted 1: inverted this bit controls the polarity of the ptp output pin. when the bit is set high the ptm output pin will be inverted and not inverted when the bit is zero. it has no ef fect if the ptm is in the t imer/counter mode. bit 1 ptcapts : ptm capture t riiger source selection 0: from ptpi pin 1: from ptck pin bit 0 ptcclr : ptm counter clear condition selection 0: comparator p match 1: comparator a match this bi t i s use d t o se lect t he m ethod whi ch c lears t he c ounter. re member t hat t he periodic t m c ontains t wo c omparators, com parator a a nd com parator p , e ither of which can be selected to clear the internal counter . w ith the ptcclr bit set high, the counter will be cleared when a compare match occurs from the comparator a. when the bit is low , the counter will be cleared when a compare match occurs from the comparator p or with a counter overfow . a counter overfow clearing method can only be implemented if the ccrp bits are all cleared to zero. the ptcclr bit is not used in the pwm output, single pulse output or capture input mode.
rev. 1.40 148 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 149 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver periodic type tm operation modes the periodic t ype tm can operate in one of fve operating modes, compare match output mode, pwm output mode, single pulse output mode, capture input mode or t imer/counter mode. the operating mode is selected using the ptm1 and ptm0 bits in the ptmc1 register. compare match output mode to select this mode, bits ptm1 and ptm0 in the ptmc1 register , should be set to 00 respectively . in this mode once the counter is enabled and running it can be cleared by three methods. these are a counter overfow , a compare matc h from comparator a and a compare match from comparator p . when the ptcclr bit is low , there are two ways in which the counter can be cleared. one is when a compare match from comparator p , the other is when the ccrp bits are all zero which allows the counter t o ov erfow. he re bo th pt maf a nd pt mpf i nterrupt re quest fa gs fo r co mparator a a nd comparator p respectively, will both be generated. if the ptcclr bit in the ptmc1 register is high then the counter will be cleared when a compare match oc curs from com parator a. howe ver, he re onl y t he pt maf i nterrupt re quest fa g wi ll be generated even if the value of the ccrp bits is less than that of the ccra registers. therefore when ptcclr is high no ptmpf interru pt request fag will be generated. in the compare match output mode, the ccra can not be set to "0". as t he na me of t he m ode sugge sts, a fter a c omparison i s m ade, t he pt m out put pi n wi ll c hange state. the ptm output pin condition however only changes state when a ptmaf interrupt request fag is generated after a compare match occurs from comparator a . the p tmpf interrupt reques t fag, g enerated fr om a c ompare m atch o ccurs fr om c omparator p , wi ll h ave n o e ffect o n t he pt m output pin. the way in which the ptm output pin changes state are determined by the condition of the ptio1 and ptio0 bits in the ptmc1 register . the ptm output pin can be selected using the ptio1 and ptio0 bits to go high, to go low or to toggle from its present condition when a compare match occurs from comparator a. the initial condition of the ptm output pin, which is setup after the pt on bit changes from low to high, is setup using the pt oc bit. note that if the ptio1 and ptio0 bits are zero then no pin change will take place.
rev. 1.40 148 de?e??e? 1?? ?01? rev. 1.40 149 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value 0x3ff ccrp ccra pton ptpau ptpol ccrp int. flag ptmpf ccra int. flag ptmaf ptm o/p pin ti?e ccrp=0 ccrp > 0 counte? ove?flow ccrp > 0 counte? ?lea?ed ?y ccrp value pause resu?e stop counte? resta?t ptcclr = 0; ptm [1:0] = 00 output pin set to initial level low if ptoc=0 output toggle with ptmaf flag note ptio [1:0] = 10 a?tive high output sele?t he?e ptio [1:0] = 11 toggle output sele?t output not affe?ted ?y ptmaf flag. re?ains high until ?eset ?y pton ?it output pin reset to initial value output ?ont?olled ?y othe? pin-sha?ed fun?tion output inve?ts when ptpol is high compare match output mode C ptcclr = 0 note: 1. w ith ptcclr=0, a comparator p match will clear the counter 2. the ptm output pin is controlled only by the ptmaf fag 3. the output pin is reset to its initial state by a pton bit rising edge
rev. 1.40 1 ? 0 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?1 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value 0x3ff ccrp ccra pton ptpau ptpol ccrp int. flag ptmpf ccra int. flag ptmaf ptm o/p pin ti?e ccra=0 ccra = 0 counte? ove?flow ccra > 0 counte? ?lea?ed ?y ccra value pause resu?e stop counte? resta?t ptcclr = 1; ptm [1:0] = 00 output pin set to initial level low if ptoc=0 output toggle with ptmaf flag note ptio [1:0] = 10 a?tive high output sele?t he?e ptio [1:0] = 11 toggle output sele?t output not affe?ted ?y ptmaf flag. re?ains high until ?eset ?y pton ?it output pin reset to initial value output ?ont?olled ?y othe? pin-sha?ed fun?tion output inve?ts when ptpol is high ptmpf not gene?ated no ptmaf flag gene?ated on ccra ove?flow output does not ?hange compare match output mode C ptcclr = 1 note: 1. w ith ptcclr=1, a comparator a match will clear the counter 2. the ptm output pin is controlled only by the ptmaf fag 3. the output pin is reset to its initial state by a pton bit rising edge 4. a ptmpf fag is not generated when ptcclr =1
rev. 1.40 1?0 de?e??e? 1?? ?01? rev. 1.40 1 ? 1 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver timer/counter mode to select this mode, bits ptm1 and ptm0 in the ptmc1 register should be set to 1 1 respectively . the t imer/counter m ode operates in an identical w ay to the compare m atch o utput m ode generating the s ame interrupt flags . the exception is that in the t imer/counter m ode the p tm output pin is not used. therefore the above description and t iming diagrams for the compare match out put mod e c an be use d t o un derstand i ts fu nction. as t he pt m ou tput pi n i s no t use d i n this mode, the pin can be used as a normal i/o pin or other pin-shared function. pwm output mode to select this mode, bits ptm1 and ptm0 in the ptmc1 register should be set to 10 respectively and als o the ptio 1 and ptio 0 bits should be set to 10 res pectively. the pwm function w ithin the ptm is useful for applications which require functions such as motor control, heating control, illumination control, etc. by providing a signal of fxed frequency but of varying duty cycle on the ptm output pin, a square wave ac waveform can be generated with varying equivalent dc rms values. as both the period and duty cycle of the pwm waveform can be controlled, the choice of generated waveform is extre mely fl exible. in the pwm mode, the ptcclr bi t ha s no ef fect as the pwm period. both of the ccrp and ccra registers are used to generate the pwm waveform, one register is used to clear the internal counter and thus control the pwm waveform frequency , while the other one is used to control the duty cycl e. the pwm waveform frequency and duty cycle can therefore be controlled by the values in the ccra and ccrp registers. an interrupt fag, one for each of the ccra and ccrp , will be generated when a compare match occurs from either comparator a or comparator p . the pt oc bit in the ptmc1 register is used to select the required polarity of the pwm waveform while the two ptio1 and ptio0 bits are used to enable the pwm output or to force the ptm output pin to a fxed high or low level. the ptpol bit is used to reverse the polarity of the pwm output waveform. ? 10-bit ptm, pwm mode, ccrp 1~1023 0 pe ? iod 1~10 ? 3 10 ? 4 duty ccra if f sys =16mhz, tm clock source select f sys /4, ccrp=512 and ccra=128, the ptm pwm output frequency = (f sys /4)/512 = f sys /2048 = 7.8125khz, duty=128/512=25%, if the duty value defned by the ccra register is equal to or greater than the period value, then the pwm output duty is 100%.
rev. 1.40 1 ?? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?3 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value ccrp ccra pton ptpau ptpol ccrp int. flag ptmpf ccra int. flag ptmaf ptm o/p pin ( ptoc=1 ) ti?e counte? ?lea?ed ?y ccrp pause resu?e counte? stop if pton ?it low counte? reset when pton ?etu?ns high ptm [1:0] = 10 pwm duty cy?le set ?y ccra pwm ?esu?es ope?ation output ?ont?olled ?y othe? pin-sha?ed fun?tion output inve?ts when ptpol = 1 pwm pe?iod set ?y ccrp ptm o/p pin ( ptoc=0 ) pwm mode note: 1. the counter is cleared by ccrp. 2. a counter clear sets the pwm period 3. the internal pwm function continues running even when ptio [1:0] = 00 or 01 4. the ptcclr bit has no infuence on pwm operation
rev. 1.40 1?? de?e??e? 1?? ?01? rev. 1.40 1 ? 3 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver single pulse output mode to select this mode, bits ptm1 and ptm0 in the ptmc1 register should be set to 10 respectively and also the ptio1 and ptio0 bits should be set to 1 1 respectively . the single pulse output mode, as the name suggests, will generate a single shot pulse on the ptm output pin. the trigger for the pulse output lead ing edge is a low to high transition of the pt on bit, which can be i mplemented using t he a pplication progra m. however i n t he singl e pulse mode, t he pt on bi t can also be made to automatically change from low to high using the external ptck pin, which will in turn initiate the single pulse output. when the pt on bit transitions to a high level, the counter will start running and the pulse leading edge will be generated. the pt on bit should remain high when the pulse is in its active state. the generated pulse trailing edge will be generated when the pton bit is cleared to zero, which can be implemented using the application program or when a compare match occurs from comparator a. however a compare match from comparator a will also automatically clear the pt on bit and thus generate the single pulse output trailing edge. in this way the ccra value can be used to control the pulse width. a compare match from comparator a will also generate a ptm interrupt. the counter can only be reset back to zero when the pt on bit changes from low to high when the counter restarts. in the single pulse mode ccrp is not used. the ptcclr is not used in this mode. pton ?it 0 1 s/ w co??and set ? pton ? o? ptck pin t?ansition pton ?it 1 0 ccra t?ailing edge s/ w co??and clr ? pton ? o? ccra co?pa?e mat?h ptp output pin pulse width = ccra value ccra leading edge single pulse generation
rev. 1.40 1 ? 4 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value ccrp ccra pton ptpau ptpol ccrp int. flag ptmpf ccra int. flag ptmaf ptm o/p pin ( ptoc=1 ) ti?e counte? stopped ?y ccra pause resu?e counte? stops ?y softwa?e counte? reset when pton ?etu?ns high ptm [1:0] = 10 ; ptio [1:0] = 11 pulse width set ?y ccra output inve?ts when ptpol = 1 no ccrp inte??upts gene?ated ptm o/p pin ( ptoc=0 ) ptck pin softwa?e t?igge? clea?ed ?y ccra ?at?h ptck pin t?igge? auto. set ?y ptck pin softwa?e t?igge? softwa?e clea? softwa?e t?igge? softwa?e t?igge? single pulse mode note: 1. counter stopped by ccra 2. ccrp is not used 3. the pulse triggered by the ptck pin or by setting the pton bit high 4. a ptck pin active edge will automatically set the pton bit high. 5. in the single pulse mode, ptio [1:0] must be set to "11" and can not be changed.
rev. 1.40 1?4 de?e??e? 1?? ?01? rev. 1.40 1 ?? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver capture input mode to select this mode bits ptm1 and ptm0 in the ptmc1 register should be set to 01 respectively . this mode enables external s ignals to capture and s tore the pres ent value of the internal counter and can therefore be used for applic ations such as pulse width measurements. the external signal is supplied on the ptpi or ptck pin, selected by the ptcapts bit in the ptmc1 register . the input pin active edge can be either a rising edge, a falling edge or both rising and falling edges; the active edge transition type is selected using the ptio1 and ptio0 bits in the ptmc1 register . the counter is s tarted w hen the p ton bit changes from low to high w hich is initiated us ing the application program. when the required edge transition appears on the ptpi or ptck pin the present value in the counter will be latched into the ccra registers and a ptm interrupt generated. irrespective of what events occur o n t he pt pi o r pt ck p in t he c ounter wi ll c ontinue t o f ree r un u ntil t he pt on b it c hanges from high to low . when a ccrp compare match occurs the counter will reset back to zero; in this way t he ccrp val ue c an be use d t o c ontrol t he m aximum c ounter val ue. whe n a ccrp c ompare match occurs from comparator p , a ptm interrupt will also be generated. counting the number of overfow interrupt signals from the ccrp can be a useful method in measuring long pulse widths. the ptio1 and ptio0 bits can select the active trigger edge on the ptpi or ptck pin to be a rising edge, fall ing edge or both edge types. if the ptio1 and ptio0 bits are both set high, then no capture operation will take place irrespectiv e of what happens on the ptpi or ptck pin, however it must be noted that the counter will continue to run. as the ptpi or ptck pin is pin shared with other functions, care must be taken if the ptm is in the input capture mode. this is because if the pin is setup as an output, then any transitions on this pin may cause an input capture operation to be executed. the ptcclr, pt oc and ptpol bits are not used in this mode.
rev. 1.40 1 ?? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?7 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver counte? value yy ccrp pton ptpau ccrp int. flag ptmpf ccra int. flag ptmaf ccra value ti?e counte? ?lea?ed ?y ccrp pause resu?e counte? reset ptm [1:0] = 01 ptm ?aptu?e pin ptpi o? ptck xx counte? stop ptio [1:0] value xx yy xx yy a?tive edge a?tive edge a?tive edge 00 C rising edge 01 C falling edge 10 C both edges 11 C disa?le captu?e capture input mode note: 1. ptm [1:0] = 01 and active edge set by the ptio [1:0] bits 2. a ptm capture input pin active edge transfers the counter value to ccra 3. ptcclr bit not used 4. no output function C ptoc and ptpol bits are not used 5. ccrp determines the counter value and the counter has a maximum count value when ccrp is equal to zero.
rev. 1.40 1?? de?e??e? 1?? ?01? rev. 1.40 1 ? 7 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver analog to digital converter the need to interface to real world analog signals is a common requirement for many electronic systems. however , to properly process these signals by a microcontroller , they must first be converted into digital signals by a/d converters. by integrating the a/d conversion electronic circuitry into the microcontroller , the need for external components is reduced signifcantly with the corresponding follow-on benefts of lower costs and reduced component space requirements. a/d converter overview these devices contain a multi-channel analog to digital converter which can directly interface to external analog signals, such as that from sensors or other control signals and convert these signals directly into a 12-bit digital value. it also can convert the internal signals, such as the t emperature semsor output or t emperature sensor reference voltage, into a 12-bit digital value. the external or internal analog signal to be convert ed is determined by the acs3~acs 0 bits together with the tse and bgmen bits. when the external analog signal is to be converted, the corresponding pin-shared control bits should frst be properly confgured and then desired external channel input should be selected using the acs3~acs0 bits. this a/ d c onverter a lso i ncludes a t emperature se nsor c ircuitry whic h c ontains a t emperature sensor, operationa l amplifers and an internal reference voltage. the temperature sensor will detect the t emperature a nd out put a vol tage proporti onal t o t he t emperature. t he out put vol tage c an be amplifed by the opa and then converted to an 12-bit digital data using the a/d converter. the accompanying block diagram shows the internal structure of the a/d converter with temperature sensor together with its associated registers and control bits. device external input channels internal signal a/d channel select bits bs ?? f340 bs ?? f3 ? 0 bs ?? f3 ? 0 bs ?? f370 8: an0~an7 ? : v tso ? v tsvref acs3~acs0 tse ? bgmen pin - sha?ed sele?tion acs 3~ acs 0 a/ d conve?te? start adbz v ss a/ d clo?k ? n (n=0~7) f sys adck ?~ adck 0 v dd adcen adrl adrh an 0 an 1 an 7 a/ d conve?te? refe?en?e voltage a/ d data registe?s adrfs vref pin - sha?ed sele?tion idle _ conv atm te?p . senso? tse bgmen v bgts v ptat opa 1 gain =1. ?7? o? 1 k_ vptat op 1 en k_ refo opa ? op ? en gain = 4 o? ? g? xen v tso v dd tse bgmen v tsvref vrefp _ ext 1xxxb v tso v tsvref v ptat tsclk _s1~ tsclk _s0 vrefs v tsvri bias v tsvref v dd a/d converter with temperature sensor diagram
rev. 1.40 1 ? 8 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?9 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver registers descriptions overall operation of the a/d converter with t emperature sensor is controlled using eight registers. a read only register pair exists to store the a/d converter data 12-bit value. t wo registers, adcr0 and adcr1, are the control registers which setup the operating and control function of the a/d converter. the remaining four registers are the temperature sensor control registers which select the t emperature se nsor si gnal t o b e c onverted a nd t he r eference v oltage so urce t ogether wi th t he temperature sensor conversion clock cycles. register name bit 7 6 5 4 3 2 1 0 adrl (adrfs=0) d3 d ? d1 d0 adrl (adrfs=1) d7 d ? d ? d4 d3 d ? d1 d0 adrh (adrfs=0) d11 d10 d9 d8 d7 d ? d ? d4 adrh (adrfs=1) d11 d10 d9 d8 adcr0 start adbz adcen adrfs acs3 acs ? acs1 acs0 adcr1 atm idle_ conv vrefs adck ? adck1 adck0 tsc0 bgmen g ? xen k_refo tsc1 tse op ? en op1en tsc ? vrefp_ext bias d ? d4 d3 d ? tsclk_s1 tsclk_s0 tsc3 k_vptat a/d converter with temperature sensor registers list a/d converter data registers C adrl, adrh as these devices contain an internal 12-bit a/d converter , it requires two data registers to store the converted va lue. t hese a re a hi gh byt e register, kn own a s adr h, a nd a l ow byt e re gister, kno wn as adrl. after the conversion process takes place, these registers can be directly read by the microcontroller to obtain the digitised conversion value. as only 12 bits of the 16-bit register space is utilised, the format in which the data is stored is controlled by the adrfs bit in the adcr0 register as shown in the accompany ing table. d0~d1 1 are the a/d conversion result data bits. any unused bits will be read as zero. note that the a/d data register conten ts can only be read in the a/ d conversion completion interrupt service subroutine when the auto-conversion mode is enabled by setting the a tm bit in the adcr1 register to 1. the a/d data registe rs contents will be cleared to zero if the a/d converter is disabled. adrfs adrh adrl 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 0 d11 d10 d9 d8 d7 d ? d ? d4 d3 d ? d1 d0 0 0 0 0 1 0 0 0 0 d11 d10 d9 d8 d7 d ? d ? d4 d3 d ? d1 d0 a/d converter data registers
rev. 1.40 1?8 de?e??e? 1?? ?01? rev. 1.40 1 ? 9 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver a/d converter control registers C adcr0, adcr1 to control the function and operatio n of the a/d converter , two control registers known as adcr0 and adcr1 are provided. these 8-bit registers define functions such as the selection of which analog channel is connected to the internal a/d converter , the digitised data format, the a/d clock source as well as controlling the start function and monitoring the a/d converter busy status. as these de vices c ontain on ly on e a ctual a nalog t o di gital c onverter ha rdware c ircuit, e ach of t he external and internal analog signals must be routed to the converter . the acs3~acs0 bits in the adcr0 register and the tse and bgmen bits in the tsc1 and tsc0 registers are used to determine that the specifc external channel input or relevant internal temperature sensor signal is selected to be converted. if the internal temperature sensor analog signal is selected to be converted, the acs3~acs0 bits should be set as "1xxx" toge ther wit h proper configurati ons of tse and bgmen bits. tse bgmen acs3~acs0 input signals description 0 x x000~x111 an0~an7 exte ? nal ? hannel analog input 1 0 1xxx v tso te ? pe ? atu ? e senso ? output voltage 1 1 1xxx v tsvref te ? pe ? atu ? e senso ? ? efe ? en ? e voltage a/d converter input signal selection the relev ant pin-shared function selection bits determine which pins on i/o ports are used as analog inputs for the a/d converter input and which pins are not to be used as the a/d converter input. when the pin is selected to be an a/d input, its original function whether it is an i/o or other pin- shared function will be removed. in addition, any internal pull-high resistor connected to the pin will be automatically removed if the pin is selected to be an a/d converter input. ? adcr0 register bit 7 6 5 4 3 2 1 0 na ? e start adbz adcen adrfs acs3 acs ? acs1 acs0 r/w r/w r r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7 start : start the a/d conversion 0 1 0: start this bit is used to initiate an a/ d conversion process. the bit is normally low but if set high and then cleared low again, the a/d converter will initiate a conversion process. bit 6 adbz : a/d converter busy fag 0: no a/d conversion is in progress 1: a/d conversion is in progress this read only fag is us ed to indicate w hether the a /d convers ion is in progress or not. when the st art bit is set from low to high and then to low again, the adbz fag will be set to 1 to indicate that the a/d conversion is initiated. the adbz fag will be cleared to 0 after the a/d conversion is complete. bit 5 adcen : a/d converter function enable control 0: disable 1: enable this bit controls the a/d internal function. this bit should be set to one to enable the a/ d c onverter. if t he bi t i s se t l ow, t hen t he a/ d c onverter wi ll be swi tched of f reducing the device power consumption. when the a/d converter function is disabled, the conte nts of the a/d data register pair known as adrh and adrl will be cleared to zero.
rev. 1.40 1 ? 0 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?1 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 4 adrfs : a/d conversion data format select 0: a/d converter data format adrh = d [11:4]; adrl = d [3:0] 1: a/d converter data format adrh = d [11:8]; adrl = d [7:0] this bit controls the format of the 12-bit converted a/d value in the two a/d data registers. details are provided in the a/d converter data register section. bit 3~0 acs3~acs0 : a/d converter analog input signal select 0000: external an0 input 0001: external an1 input 0010: external an2 input 0011: external an3 input 0100: external an4 input 0101: external an5 input 0110: external an6 input 0111: external an7 input 1xxx: internal signal from temperature sensor C temperature output voltage or reference voltage the "1xxx" selection is only available when the tse bit is set to 1. t o select the internal temperature sensor signal to be converted, these bits must be set as "1xxx" when the tse bit is set to 1. otherwise, these bits are used to select the external ann channel input without the regard of the acs3 value if the tse bit is cleared to 0. ? adcr1 register bit 7 6 5 4 3 2 1 0 na ? e atm idle_conv vrefs adck ? adck1 adck0 r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 bit 7 atm : a/d auto-conversion mode enable control 0: disable 1: enable when t his bi t i s se t t o 1, t he a/ d c onverter wi ll c ontinuously pe rform t he da ta conversion after the current conversion is complete without confguring the "st art" bit by application program. note that the a/d conversion data can only be read in the a/d c onversion c ompletion i nterrupt se rvice su broutine wh en t he a/ d auto-conversion mode is enabled. bit 6 unimplemented, read as "0" bit 5 idle_conv : cpu idle conversion mode enable control 0: disable 1: enable when this bit is set to 1, the a/d conversion with cpu idle mode will be enabled. the cpu will not operate when the a/d converter is operating with the idle_conv bit being set to 1 until the conversion is completed. bit 4 vrefs : a/d converter reference voltage select 0: internal a/d converter power 1: vref pin this bit is used to select the a/d converter reference voltage and only available when the vrefp_ext bit in the tsc2 register is set to 1. it is recommended to keep the vrefp_ext bit low when the internal temperature sensor signal is selected to be converted. bit 3 unimplemented, read as "0"
rev. 1.40 1?0 de?e??e? 1?? ?01? rev. 1.40 1 ? 1 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 2~0 adck2~adck0 : a/d conversion clock source select 000: f sys 001: f sys /2 010: f sys /4 011: f sys /8 100: f sys /16 101: f sys /32 110: f sys /64 111: f sys /128 these bits are used to select the cloc k source for the a/d converter . it is recommended that the a/d conversion clock frequency should be in the range from 500 khz to 1mhz by properly configuring the adck2~adck0 bits when the internal temperature sensor signal is selected to be converted as temperature sensor enabled, ? tsc0 register bit 7 6 5 4 3 2 1 0 na ? e bgmen g ? xen k_refo r/w r/w r/w r/w por 0 1 0 bit 7 bgmen : t emperature sensor reference voltage output function enable control 0: disable 1: enable this bi t c ontrols t he i nternal t emperature se nsor re ference vo ltage ou tput fu nction and is only available when the tse bit is set to 1. the internal temperature sensor reference voltage can be converted when the tse and bg men bits are set to 1 and the acs bit field is set to "1xxx". however , the internal temperature sensor output voltage will be converted if the tse bit is set to 1 and the bgmen bit is cleared to 0 together with acs bit feld equal to "1xxx". bit 6 g5xen : opa2 gain select 0: gain=4 1: gain=5 this bit controls the op a2 gain selection. this bit should be properly selected for different temperature range applications to avoid the saturated code. bit 5 k_refo : opa1 gain select 0: gain=1.675 1: gain=1 this bit is used to select the op a1 gain to determine the temperature sensor reference voltage output value. bit 4~0 unimplemented, read as "0" ? tsc1 register bit 7 6 5 4 3 2 1 0 na ? e tse op ? en op1en r/w r/w r/w r/w por 0 0 0 bit 7 tse : t emperature sensor circuitry enable control 0: disable 1: enable this bit controls the internal temperature sensor circuitry. when the temperature sensor is enable d by setting the tse bit to 1, a time named as t tss should be allowed for the temperature sensor circuit to stabilise before implementing relevant temperature sensor operation.
rev. 1.40 1 ?? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?3 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 6 op2en : t emperature sensor opa2 enable control 0: disable 1: enable bit 5 op1en : t emperature sensor opa1 enable control 0: disable 1: enable bit 4~0 unimplemented, read as "0" ? tsc2 register bit 7 6 5 4 3 2 1 0 na ? e vrefp_ext bias d ? d4 d3 d ? tsclk_s1 tsclk_s0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7 vrefp_ext : a/d converter positive reference voltage select 0: t emperature reference voltage C v tsvref 1: determined by vrefs bit this bit is used to select the a/d converter positive reference voltage. when this bit is set to 1, the a/d converter reference voltage is determines by the vrefs bit in the adcr1 register . however , this bit should be set low to select the v tsvref voltage as the a/d converter reference voltage together with proper confgurations of the op a2 input signal and gain. bit 6 bias : opa2 bias voltage select 0: v tsvref 1: internal a/d converter power bit 5~2 d5~d2 : data bits for internal used these bits should be kept low and can not be changed. bit 1~0 tsclk_s1~tsclk_s0 : t emperature sensor clock source t tsclk select 00: t tsclk = t adck /4 01: t tsclk = t adck /8 1x: t tsclk = t adck /16 the temperature sensor signal conversion time can be obtained using the equation: temperature sensor signal conversion time = (5 n+1+16) t adck in the above equation "n" represents the divided ratio, 4, 8 or 16, which is determined by the tsclk_s1 and tsclk_s0 bits. ? tsc3register bit 7 6 5 4 3 2 1 0 na ? e k_vptat r/w r/w por 0 bit 7~6 unimplemented, read as "0" bit 5 k_vptat : opa1 input voltage select 0: v bg 1: v p tat this bit is used to select the op a1 input voltage to obtain the internal temperature sensor reference voltage. bit 4~0 unimplemented, read as "0"
rev. 1.40 1?? de?e??e? 1?? ?01? rev. 1.40 1 ? 3 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver a/d converter operation the st art bit in the adcr0 register is used to start the ad conversion. when the microcontroller sets this bit from low to high and then low again, an analog to digital conversion cycle will be initiated. the adbz bit in the adcr0 register is used to indicate whether the analog to digital conversion process is in progress or not. this bit will be automatically set to 1 by the microcontroller after an a/d conversion is successfully initiated. when the a/d conversion is complete, the adbz will be cleared to 0. in addition, the corresponding a/d interrupt request fag will be set in the interrupt control register , and if the interrupts are enabled, an internal interrupt signal will be generated. this a/d internal interrupt s ignal w ill direct the program f ow to the as sociated a /d internal interrupt address f or p rocessing. i f t he a/ d i nternal i nterrupt i s d isabled, t he m icrocontroller c an p oll t he adbz bit in the adcr0 register to check whether it has been cleared as an alternative method of detecting the end of an a/d conversion cycle. the clock source for the a/d converter , which originates from the system clock f sys , can be chosen to be either f sys or a subdivided version of f sys . the division ratio value is determined by the sacks2~sacks0 bits in the sadc1 register . although the a/d cloc k source is determined by the system clock f sys and by bi ts adck2~adck0, there are som e limi tations on the maximum a/d clock source speed that can be selected. as the recommended range of permissible a/d clock period, t adck , is from 0.5s to 10s, care must be taken for system clock frequencies. for example, as the system clock operates at a frequency of 8mhz, the adck2~adck0 bits should not be set to 000, 001 or 1 11. doing so will give a/d clock periods that are less than the minimum a/d clock period which m ay re sult i n i naccurate a/ d c onversion va lues. re fer t o t he fol lowing t able for e xamples, where values marked with an asteri sk * show where, depending upon the device, special care must be taken, as the values may be less than the specifed minimum a/d clock period. however, the recommended a/d clock period is from 1s to 2s if the input signal to be converted is the temperature sensor output voltage or reference voltage. f sys a/d clock period (t adck ) adck[2:0] = 000 (f sys ) adck[2:0] = 001 (f sys /2) adck[2:0] = 010 (f sys /4) adck[2:0] = 011 (f sys /8) adck[2:0] = 100 (f sys /16) adck[2:0] = 101 (f sys /32) adck[2:0] = 110 (f sys /64) adck[2:0] = 111 (f sys /128) 1 mhz 1s 2s 4s 8s 16s * 32s * 64s * 128s * ? mhz ? 00ns 1s 2s 4s 8s 16s * 32s * 64s * 4 mhz ?? 0ns * ? 00ns 1s 2s 4s 8s 16s * 32s * 8 mhz 1 ?? ns * ?? 0ns * ? 00ns 1s 2s 4s 8s 16s * 1 ? mhz 83ns * 1 ? 7ns * 333ns * ?? 7ns 1.33s 2.67s 5.33s 10.67s * 1 ? mhz ?? . ? ns * 1 ?? ns * ?? 0ns * ? 00ns 1s 2s 4s 8s ? 0 mhz ? 0ns * 100ns * ? 00ns * 400ns * 800ns 1.6s 3.2s 6.4s a/d clock period examples for external analog inputs however, the recommended a/d clock period is from 1s to 2s if the input signal to be converted is the temperature sensor output voltage or reference voltage. controlling t he powe r on/ off func tion of t he a/ d c onverter c ircuitry i s i mplemented usi ng t he adcen bi t i n t he adcr 0 re gister. t his bi t m ust be se t hi gh t o powe r on t he a/ d c onverter. when the adcen bit is set high to power on the a/d converter internal circuitry a certain delay , as indica ted in the timing diagram, must be allowed before an a/d conversion is initiated. even if no pins are selected for use as a/d inputs, if the adcen bit is high, then some power will still be consumed. in power conscious applications it is therefore recommended that the adcen is set low to reduce power consumption when the a/d converter function is not being used.
rev. 1.40 1 ? 4 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver a/d converter reference voltage the reference voltage supply to the a/d converter can be supplied from the positive power supply pin, v dd , a n e xternal re ference sourc e suppl ied on pi n vr ef or a n i nternal t emperature se nsor reference voltage v tsvref . the internal temperature sensor reference voltage can be derived from the intenal v bg or v p tat voltage selected using the k_vptat bit in the tsc3 register and then amplifed through a p rogrammable g ain a mplifier e xcept t he o ne so urced f rom v dd . t he pga g ain c an b e equal to 1.675 or 1 selected by the k_refo bit in the tsc0 register . as the vref pin is pin-shared with other functio ns, when the vref pin is selected as the reference voltage supply pin, the vref pin-shared function control bits should first be properly configured to disable other pin-shared functions. a/d converter input pins all of the external a/d analog input pins are pin-shared with the i/o pins as well as other functions. the c orresponding p in-shared f unction se lection b its i n t he px s0 a nd px s1 r egisters, d etermine whether the external input pins are setup as a/d converter analog channel inputs or whether they have other functio ns. if the corresponding pin is setup to be an a/d converter analog channel input, the original pin functions will be disabled. in this way , pins can be changed under program control to change their function between a/d inputs and other functions. all pull-high resistors, which are setup through register programming, will be automatically disconnecte d if the pins are setup as a/d inputs. note that it is not necessary to frst setup the a/d pin as an input in the port control register to enable the a/d input as when the relevant a/d input function select ion bits enable an a/d input, the status of the port control register will be overridden. the a /d converter has its ow n reference voltage pin, v ref. h owever, the reference voltage can also be supplied from the power supply pin or an internal temperature sensor circuit, a choice which is made through the vrefp_ext and vrefs bits in the tsc2 and adcr1 register respectively . note that the anal og input signal values must not be allowed to exceed the value of the selected a/d reference voltage. conversion rate and timing diagram a com plete a/d conversi on contains two parts, dat a sampli ng and dat a conversi on. the dat a sampling which is defned as t ads takes 4 a/d clock cycles and the data conversion takes 12 a/d clock cycles. therefore a total of 16 a/d clock cycles for an external input a/d conversion which is defned as t adc are necessary . however , an a/d conversion for an inter nal temperatur e sensor signal will take a total of 56 a/d clock cycles. maximum single a/d conversion rate = a/d clock period / 16 (external channel input signal) maximum si ngle a/ d conversion rate = a/ d clock pe riod / 56 (i nternal t emperature se nsor si gnal) the accompanying diagram shows graphically the various stages involved in an analog to digital conversion process and its associated timing. after an a/d conversion process has been initiated by the application program, the microcontroller internal hardware w ill begin to carry out the conversion, d uring wh ich t ime t he p rogram c an c ontinue wi th o ther f unctions. t he t ime t aken f or t he a/d conversion is 16 t adck clock cycles where t adck is equal to the a/d clock period.
rev. 1.40 1?4 de?e??e? 1?? ?01? rev. 1.40 1 ?? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver adcen start adbz acs [3:0] off on off on t on ? st t ads a/ d sa?pling ti?e t ads a/ d sa?pling ti?e sta?t of a / d ?onve?sion sta?t of a / d ?onve?sion sta?t of a / d ?onve?sion end of a / d ?onve?sion end of a / d ?onve?sion t adc a/ d ?onve?sion ti?e t adc a/ d ?onve?sion ti?e t adc a/ d ?onve?sion ti?e x 011 b x 010b x 000b x 001b a/ d ?hannel swit?h ( tse =0) a/d conversion timing C external channel input summary of a/d conversion steps the following summarises the individual steps that should be executed in order to implement an a/d conversion process. ? step 1 select the required a/d conversion clock by properly programming the adck2~adck0 bits in the adcr1 register. ? step 2 enable the a/d converter by setting the adcen bit in the adcr0 register to one. ? step 3 select which signal is to be connec ted to the internal a/d converter by correctly confguring the acs3~acs0 bits if the tse bit is 0 and acs3~acs0 bits are equal to x000~x1 11, then an external channel input is selected. if the tse bit is 1 and acs3~acs0 bits are equal to 1xxx, then the relevant internal temperature sensor signal is selected. ? step 4 select the reference voltgage source by confguring the k_vptat, k_refo and vrefs bits. ? step 5 select the a/d converter output data format by confguring the adrfs bit. ? step 6 if a/d conversion interrupt is used, the interrupt control registers must be correctly confgured to ensure the a/d interrupt function is active. the master interrupt bontrol bit, emi, and the a/d conversion interrupt control bit, ade, must both be set high in advance. ? step 7 the a/d conversion procedure can now be initialized by setting the st art bit from low to high and then low again. ? step 8 if a/ d conversi on i s i n progre ss, t he adbz fla g wi ll be se t high. aft er t he a/ d conversi on process is complete, the adbz fag will go low and then the output data can be read from adrh and adrl registers. note: when checking for the end of the conversion process, if the met hod of polling the adbz bit in the adcr0 register is used, the interrupt enable step above can be omitted. however , the interrupt method must be used to check for the end of the conversion process and obtain the corresponding digital output data if the auto-conversion mode is enabled.
rev. 1.40 1 ?? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?7 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver programming considerations during m icrocontroller ope rations where t he a/d c onverter i s not be ing used, t he a/d i nternal circuitry can be switched of f to reduce power consumption, by setting bit adcen low in the adcr register. when this happens, the inte rnal a/d converter circuits will not consume power irrespective of what analog voltage is applied to their input lines. if the a /d converter input lines are used as normal i/os, then care must be taken as if the input voltage is not at a valid logic level, then this may lead to some increase in power consumption. a/d converter transfer function as the devices contain a 12-bit a/d converter , its full-scale converted digitised value is equal to fffh. since the full-scale analog input value is equal to the reference voltage, this gives a single bit analog input value of reference voltage value divided by 4096. 1 lsb = v ref 4096 the a/d converter input voltage value can be calculated using the following equation: a/d input voltage = a/d output digital value v ref 4096 the diagram shows the ideal transfer function between the analog input value and the digitised output val ue for t he a/ d conve rter. e xcept for t he di gitised ze ro val ue, t he subsequent digi tised values will change at a point 0.5 lsb below where they would change without the of fset, and the last full scale digitised value will change at a point 1.5 lsb below the v ref level.               

 
 
  
  
 
 
 
 ?  ? ? ? ? ?  ??    ?   
 ? ideal a/d transfer function
rev. 1.40 1?? de?e??e? 1?? ?01? rev. 1.40 1 ? 7 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver a/d programming examples the following two programming examples illustrate how to setup and implement an a/d conversion. in the frst example, the method of polling the adbz bit in the adcr register is used to detect when the conversion cycle is complete, whereas in the second example, the a/d interrupt is used to determine when the conversion is complete. example: using an adbz polling method to detect the end of conversion clr ade ; disable adc interrupt set vrefp_ext ; deselect the temperature sensor reference voltage mov a,03h ; select f sys /8 as a/d clock and a/d internal power supply mov adcr1,a ; as reference voltage set adcen mov a,03h ; setup pbs0 to confgure pin an0 mov pbs0,a mov a,20h mov adcr0,a ; enable and connect an0 channel to a/d converter : start_conversion: clr start ; high pulse on start bit to initiate conversion set start ; reset a/d clr start ; start a/d : polling_eoc: sz adbz ; poll the adcr0 register adbz bit to detect end of a/d conversion jmp polling_eoc ; continue polling : mov a,adrl ; read low byte conversion result value mov adrl_buffer,a ; save result to user defned register mov a,adrh ; read high byte conversion result value mov adrh_buffer,a ; save result to user defned register : jmp start_conversion ; start next a/d conversion
rev. 1.40 1 ? 8 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 1?9 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver example: using the interrupt method to detect the end of conversion clr ade ; disable adc interrupt set vrefp_ext ; deselect the temperature sensor reference voltage mov a,03h ; select f sys /8 as a/d clock and a/d internal power supply mov adcr1,a ; as reference voltage set adcen mov a,03h ; setup pbs0 to confgure pin an0 mov pbs0,a mov a,20h mov adcr0,a ; enable and connect an0 channel to a/d converter : start_conversion: clr start ; high pulse on start bit to initiate conversion set start ; reset a/d clr start ; start a/d clr adf ; clear adc interrupt request fag set ade ; enable adc interrupt set emi ; enable global interrupt : : adc_isr: ; adc interrupt service routine mov acc_stack,a ; save acc to user defned memory mov a,status mov status_stack,a ; save status to user defned memory : mov a, adrl ; read low byte conversion result value mov adrl_buffer,a ; save result to user defned register mov a, adrh ; read high byte conversion result value mov adrh_buffer,a ; save result to user defned register : exit_int_isr: mov a,status_stack mov status,a ; restore status from user defned memory mov a,acc_stack ; restore acc from user defned memory reti
rev. 1.40 1?8 de?e??e? 1?? ?01? rev. 1.40 1 ? 9 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver serial interface module C sim these devices contain a serial interface module, which includes both the four -line spi interface or two-line i 2 c interface types, to allow an easy method of communication with external peripheral hardware. ha ving re latively si mple c ommunication prot ocols, t hese se rial i nterface t ypes a llow the microcontroller to interface to external spi or i 2 c based hardware such as sensors, flash or eeprom memory , etc. the sim interface pins are pin-shared with other i/o pins and therefore the sim i nterface func tional pi ns m ust fi rst be se lected usi ng t he c orresponding pi n-shared func tion selection bits. as both interface types share the same pins and registers, the choice of whether the spi or i 2 c type is used is made using the sim operating mode control bits, named sim2~sim0, in the simc0 registe r. these pull-high resistors of the sim pin-shared i/o pins are selected using pull- high control registers when the sim function is enabled and the corresponding pins are used as sim input pins. spi interface the spi interface is often used to communicate with external peripheral devices such as sensors, flash or e eprom m emory de vices, e tc. ori ginally de veloped by mot orola, t he four l ine spi interface is a synchronous serial data interface that has a relatively simple communication protocol simplifying the programming requirements when communicating with external hardware devices. the communication is full duplex and operates as a slave/master type, where the devices can be either mas ter or s lave. a lthough the s pi interface s pecifcation can control multiple s lave devices from a single master , these devices provided only one scs pin. if the master needs to control multiple slave devices from a single master, the master can use i/o pin to select the slave devices. spi interface operation the spi i nterface i s a f ull d uplex sy nchronous se rial d ata l ink. i t i s a f our l ine i nterface wi th p in names sdi, sdo, sck and scs . pins sdi and sdo are the serial data input and serial data output lines, sck is the serial clock line and scs is the slave select line. as the spi interface pins are pin-shared with normal i/o pins and with the i 2 c function pins, the spi interface pins must frst be selected by confguring the pin-shared function selection bits and setting the correct bits in the simc0 and simc2 registers. after the desired spi confguration has been set it can be disabled or enabled us ing the s imen bit in the s imc0 regis ter. communication betw een devices connected to t he spi i nterface i s c arried out i n a sl ave/master m ode wi th a ll da ta t ransfer i nitiations be ing implemented by the master . the master also controls the clock signal. as the device only contains a single scs pin only one slave device can be utilized. the scs pin is controlled by software, set csen bit to 1 to enable scs pin function, set csen bit to 0 the scs pin will be foating state. the spi function in this device offers the following features: ? full duplex synchronous data transfer ? both master and slave modes ? lsb frst or msb frst data transmission modes ? transmission complete fag ? rising or falling active clock edge the status of the spi interface pins is determined by a number of facto rs such as whether the device is in the master or slave mode and upon the condition of certain control bits such as csen and simen.
rev. 1.40 170 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 171 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver                        spi master/slave connection                   
        
   
   ??
                   ?    ?     ?? ?  ? ?- ?   ?  ?   ?   ?    ?    ? spi block diagram spi registers there are three internal registers which control the overall operation of the spi interface. these are the simd data register and two registers simc0 and simc2. note that the simc1 register is only used by the i 2 c interface. register name bit 7 6 5 4 3 2 1 0 simc0 sim ? sim1 sim0 simdeb1 simdeb0 simen simicf simc ? d7 d ? ckpolb ckeg mls csen wcol trf simd d7 d ? d ? d4 d3 d ? d1 d0 spi registers list ? simd register the simd register is used to store the data being transmitted and received. the same register is used by both the spi and i 2 c functions. before the device writes data to the spi bus, the actual data to be transmitted must be placed in the simd register . after the data is received from the spi bus, the device can read it from the simd register . any transmission or reception of data from the spi bus must be made via the simd register. bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por x x x x x x x x "x": unknown
rev. 1.40 170 de?e??e? 1?? ?01? rev. 1.40 171 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver there are also two control registers for the spi interface, simc0 and simc2. note that the simc2 register also has the name sima which is used by the i 2 c function. the simc1 register is not used by the spi functio n, only by the i 2 c function. register simc0 is used to control the enable/disable function and to set the data transmi ssion clock frequency . register simc2 is used for other control functions such as lsb/msb selection, write collision fag, etc. ? simc0 register bit 7 6 5 4 3 2 1 0 na ? e sim ? sim1 sim0 simdeb1 simdeb0 simen simicf r/w r/w r/w r/w r/w r/w r/w r/w por 1 1 1 0 0 0 0 bit 7~5 sim2~sim0 : sim operating mode control 000: spi master mode; spi clock is f sys /4 001: spi master mode; spi clock is f sys /16 010: spi master mode; spi clock is f sys /64 011: spi master mode; spi clock is f sub 100: spi master mode; spi clock is ctm0 ccrp match frequency/2 101: spi slave mode 110: i 2 c slave mode 111: non sim function these bits setup the overall operatin g mode of the sim function. as well as selecting if the i 2 c or spi function, they are used to control the spi master/slav e selection and the spi master clock frequency . the spi clock is a function of the system clock but can also be chosen to be sourced from ctm0. if the spi slave mode is selected then the clock will be supplied by an external master device. bit 4 unimplemented, read as "0" bit 3~2 simdeb1~simdeb0 : i 2 c debounce t ime selection described elsewhere. bit 1 simen : sim enable control 0: disable 1: enable the bi t is the overa ll on/of f control for the sim interface. when the simen bi t is cleared to zero to disable the sim interface, the sdi, sdo, sck and scs , or sda and scl lines will lose their spi or i 2 c function and the sim operating current will be reduced to a mini mum value. when the bit is high the sim interface is enabled. the sim confguration option must have frst enabled the sim interface for this bit to be effective.if the sim is confgured to operate as an spi interface via the sim2~sim0 bits, the contents of the spi control registers will remain at the previous settings when the simen bit changes from low to high and should therefore be frst initiali sed by the applic ation program. if the sim is confgured to operate as an i 2 c interface via the sim2~sim0 bits and the simen bit changes from low to high, the contents of the i 2 c control bits such as htx and txak will remain at the previous setti ngs and should therefore be first initialised by the application program while the relevant i 2 c flags such as hcf, haas, hbb, srw and rxak will be set to their default states. bit 0 simicf : sim spi slave mode incomplete t ransfer flag 0: sim spi slave mode incomplete condition not occurred 1: sim spi slave mode incomplete condition occured this bit is only available when the sim is confgured to operate in an spi slave mode. if the spi operate s in the slave mode with the simen and csen bits both being set to 1 but the scs line is pulled high by the external master device before the spi data transfer is completely fnished, the simicf bit will be set to 1 togethe r with the trf bit. when this condition occurs, the corresponding interrupt will occur if the interrupt function is enabled. however , the trf bit will not be set to 1 if the simicf bit is set to 1 by software application program.
rev. 1.40 17 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 173 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? simc2 register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? ckpolb ckeg mls csen wcol trf r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~6 undefned bits these bits can be read or written by the application program. bit 5 ckpolb : spi clock line base condition selection 0: the sck line will be high when the clock is inactive. 1: the sck line will be low when the clock is inactive. the ckpolb bi t de termines the ba se condition of the clock line, if the bi t is hi gh, then t he sck l ine wi ll be l ow whe n t he c lock i s i nactive. w hen t he ckpol b bi t i s low, then the sck line will be high when the clock is inactive. bit 4 ckeg : spi sck clock active edge type selection ckpolb=0 0: sck is high base level and data capture at sck rising edge 1: sck is high base level and data capture at sck falling edge ckpolb=1 0: sck is low base level and data capture at sck falling edge 1: sck is low base level and data capture at sck rising edge the ckeg and ckpolb bits are used to setup the way that the clock signal outputs and inputs data on the spi bus. these two bits must be confgured before data transfer is e xecuted ot herwise a n e rroneous c lock e dge m ay be ge nerated. t he ckpol b bi t determines t he ba se c ondition of t he c lock l ine, i f t he bi t i s hi gh, t hen t he sck l ine will be low when the clock is inact ive. when the ckpolb bit is low , then the sck line will be high when the clock is inactive. the ckeg bit determines active clock edge type which depends upon the condition of ckpolb bit. bit 3 mls : spi data shift order 0: lsb frst 1: msb frst this is the data shift select bit and is used to select how the data is transferred, either msb or lsb frst. setting the bit high will select msb frst and low for lsb frst. bit 2 csen : spi scs pin control 0: disable 1: enable the csen bit is used as an enable/disable for the scs pin. if this bit is low , then the scs pin will be disabled and placed into i/o pin or other pin-shared functions. if the bit is high, the scs pin will be enabled and used as a select pin. bit 1 wcol : spi write collision fag 0: no collision 1: collision the wcol fag is used to detect whether a data collision has occurred or not. if this bit is high, it means that data has been attempted to be written to the simd register duting a data transfer operation. this writing operation will be ignored if data is being transferred. this bit can be cleared by the application program. bit 0 trf : spi t ransmit/receive complete fag 0: spi data is being transferred 1: spi data transfer is completed the trf bit is the t ransmit/receive complete fag and is set to 1 automatically when an spi data transfer is completed, but must cleared to 0 by the application program. it can be used to generate an interrupt.
rev. 1.40 17? de?e??e? 1?? ?01? rev. 1.40 173 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver spi communication after t he spi i nterface i s e nabled by se tting t he sime n bi t hi gh, t hen i n t he ma ster mode , whe n data is written to the simd register , transmission/reception will begin simultaneously . when the data t ransfer i s c omplete, t he t rf fl ag wi ll be se t a utomatically, but m ust be c leared usi ng t he application program. in the slave mode, when the clock signal from the master has been received, any data in the simd register will be transmitted and any data on the sdi pin will be shifted into the simd register . the master should output a scs signal to enable the slave devices before a clock signal is provided. the slave data to be transferred should be well prepared at the appropriate moment relative to the scs signal depending upon the confgurations of the ckpolb bit and ckeg bit. the accompanying timing diagram shows the relationship between the slave data and scs signal for various confgurations of the ckpolb and ckeg bits. the spi will continue to function even in the idle mode.                         
                                      ?      ?        ? ?    ? 
?? ?? ? ?? ? ?? ?? -? ?? ?? ?? ?? ?? -? ?? ? ?? ?? ? ?? ?? ?? ? ?? ? ?? ?? -? ?? ?? ?? ?? ?? -? ?? ? ?? ?? ? ?? ? 
 ?   ? spi master mode timing                       
                  
         ?  ? ? ? ???  ? - ?  ?    ??  spi slave mode timing C ckeg = 0
rev. 1.40 174 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 17? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver                       
                  
         ? ? ?? ?  ?? ?  ? ?   ??  ?? ? -   ? ??   ?? ?   ?  ??    ? ? ? ? ? ? ?   ??   ??  ?? ?    ? ? ? ??  ? ?? ? ?? ? ? ?  ?   ? ? ? ? note: for spi slave mode, if simen=1 and csen=0, the spi is always enabled and ignores the scs level. spi slave mode timing C ckeg = 1                 
          
       ?       ?     
      ?     ?          
?     
?  ? ? ?   ?    ?  -?  ?? ? ? ? ? ?        ? ????  ??? ? ????? ??   ??  ? ????  ?  spi transfer control flow chart
rev. 1.40 174 de?e??e? 1?? ?01? rev. 1.40 17 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver i 2 c interface the i 2 c interface is used to communicate with external peripheral devices such as sensors, eeprom m emory e tc. or iginally d eveloped b y ph ilips, i t i s a t wo l ine l ow sp eed se rial i nterface for synchronous serial data transfer . the advantage of only two lines for communication, relatively simple communication protocol and the ability to accommodate multiple devices on the same bus has made it an extremely popular interface type for many applications.                         i 2 c master slave bus connection i 2 c interface operation the i 2 c serial interface is a two line interf ace, a serial data line, sda, and serial clock line, scl. as many devices may be connected together on the same bus, their outputs are both open drain types. for this reason it is necessary that external pull-high resistors are connected to these outputs. note that no chip select line exists, as each device on the i 2 c bus is identifed by a unique address which will be transmitted and received on the i 2 c bus. when two device s communicate with each other on the bidirectional i 2 c bus, one is known as the master de vice a nd one a s t he sl ave de vice. bot h m aster a nd sl ave c an t ransmit a nd re ceive da ta, however, it is the master device that has overall control of the bus. for these devices, which only operate in slave mode, there are two methods of transferring data on the i 2 c bus, the slave transmit mode and the slave receive mode.                         
                      
                    ?  ?  ?         ???     ?               -      ?   ? ?   ??       ? -   ---  ? -   ? -   ?      ?  ? ?   ?  ?   ?  ?   ?- ? ?   ?- ? ? ? ?       ?  ??  -  ?  ?    

rev. 1.40 17 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 177 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver                      
                                                     the simdeb1 and simdeb0 bits determine the debounce time of the i 2 c interface. this uses the system clock to in ef fect add a debounce time to the external clock to reduce the possibility of gl itches on t he c lock l ine c ausing e rroneous ope ration. t he de bounce t ime, i f se lected, c an be chosen to be either 2 or 4 sys tem clocks. t o achieve the required i 2 c data trans fer speed, there exists a relationship between the system clock, f sys , and the i 2 c debounce time. for either the i 2 c standard or fast mode operation, users must take care of the selected system clock frequency and the confgured debounce time to match the criterion shown in the following table. i 2 c debounce time selection i 2 c standard mode (100khz) i 2 c fast mode (400khz) no devoun ? e f sys > ? mhz f sys > ? mhz ? syste ? ? lo ? k de ? oun ? e f sys > 4 mhz f sys > 10 mhz 4 syste ? ? lo ? k de ? oun ? e f sys > 8 mhz f sys > ? 0 mhz i 2 c minimum f sys frequency i 2 c registers there are three control registers associated with the i 2 c bus, simc0, simc1 and sima, and one data register , simd. the simd register , which is shown in the above spi section, is used to store the data being transmitted and received on the i 2 c bus. note that the sima register also has the name simc2 which is used by the spi function. bit simen and bits sim2~sim0 in register simc0 are used by the i 2 c interface. register name bit 7 6 5 4 3 2 1 0 simc0 sim ? sim1 sim0 simdeb1 simdeb0 simen simicf simc1 hcf haas hbb htx txak srw iamwu rxak sima iica ? iica ? iica4 iica3 iica ? iica1 iica0 d0 simd d7 d ? d ? d4 d3 d ? d1 d0 simtoc simtoen simtof simtos ? simtos4 simtos3 simtos ? simtos1 simtos0 i 2 c registers list
rev. 1.40 17? de?e??e? 1?? ?01? rev. 1.40 177 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? simd register the simd register is used to store the data being transmitted and received. the same register is used by bot h t he spi a nd i 2 c fun ctions. be fore t he de vice wri tes da ta t o t he i 2 c bus, t he a ctual da ta t o be transmitted must be placed in the simd register . after the data is received from the i 2 c bus, the device can read it from the simd register . any transmission or reception of data from the i 2 c bus must be made via the simd register. bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por x x x x x x x x "x": unknown ? sima register the sima registe r is also used by the spi interface but has the name simc2. the sima register is the location where the 7-bit slave address of the slave device is stored. bits 7~1 of the sima register defne the device slave address. bit 0 is not defned. when a master device, which is connected to the i 2 c bus, sends out an address, which matches the slave address in the sima register , the slave device will be selected. note that the sima register is the same register address as simc2 which is used by the spi interface. bit 7 6 5 4 3 2 1 0 na ? e iica ? iica ? iica4 iica3 iica ? iica1 iica0 d0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por x x x x x x x x "x": unknown bit 7~1 iica6~iica0 : i 2 c slave address iica6~iica0 is the i 2 c slave address bit 6 ~ bit 0 bit 0 undefned bit the bit can be read or written by the application program. there are also two control registers for the i 2 c interface, simc0 and simc1. the register simc0 is use d t o c ontrol t he e nable/disable func tion a nd t o se t t he da ta t ransmission c lock fre quency.the simc1 register contains the relevant fags which are used to indicate the i 2 c communication status. ? simc0 register bit 7 6 5 4 3 2 1 0 na ? e sim ? sim1 sim0 simdeb1 simdeb0 simen simicf r/w r/w r/w r/w r/w r/w r/w r/w por 1 1 1 0 0 0 0 bit 7~5 sim2~sim0 : sim operating mode control 000: spi master mode; spi clock is f sys /4 001: spi master mode; spi clock is f sys /16 010: spi master mode; spi clock is f sys /64 011: spi master mode; spi clock is f sub 100: spi master mode; spi clock is ctm0 ccrp match frequency/2 101: spi slave mode 110: i 2 c slave mode 111: non sim function these bits setup the overall operatin g mode of the sim function. as well as selecting if the i 2 c or spi function, they are used to control the spi master/slav e selection and the spi master clock frequency . the spi clock is a function of the system clock but can also be chosen to be sourced from tm0. if the spi slave mode is selected then the clock will be supplied by an external master device.
rev. 1.40 178 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 179 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 4 unimplemented, read as "0" bit 3~2 simdeb1~simdeb0 : i 2 c debounce t ime selection 00: no debounce 01: 2 system clock debounce 1x: 4 system clock debounce bit 1 simen : sim enable control 0: disable 1: enable the bi t is the overa ll on/of f control for the sim interface. when the simen bi t is cleared to zero to disable the sim interface, the sdi, sdo, sck and scs , or sda and scl lines will lose their spi or i 2 c function and the sim operating current will be reduced to a mini mum value. when the bit is high the sim interface is enabled. the sim confguration option must have frst enabled the sim interface for this bit to be effective.if the sim is confgured to operate as an spi interface via the sim2~sim0 bits, the contents of the spi control registers will remain at the previous settings when the simen bit changes from low to high and should therefore be frst initiali sed by the applic ation program. if the sim is confgured to operate as an i 2 c interface via the sim2~sim0 bits and the simen bit changes from low to high, the contents of the i 2 c control bits such as htx and txak will remain at the previous setti ngs and should therefore be first initialised by the application program while the relevant i 2 c flags such as hcf, haas, hbb, srw and rxak will be set to their default states. bit 0 simicf : sim spi slave mode incomplete t ransfer flag described elsewhere. ? simc1 register bit 7 6 5 4 3 2 1 0 na ? e hcf haas hbb htx txak srw iamwu rxak r/w r r r r/w r/w r/w r/w r por 1 0 0 0 0 0 0 1 bit 7 hcf : i 2 c bus data transfer completion fag 0: data is being transferred 1: completion of an 8-bit data transfer the hcf flag is the data transfer flag. this flag will be zero when data is being transferred. upon completion of an 8-bit data transfer the flag will go high and an interrupt will be generated. bit 6 haas : i 2 c bus data transfer completion fag 0: not address match 1: address match the haas fa g i s t he a ddress m atch fa g. t his fa g i s use d t o de termine i f t he sl ave device address is the same as the master transmit address. if the addresses match then this bit will be high, if there is no match then the fag will be low. bit 5 hbb : i 2 c bus busy fag 0: i 2 c bus is not busy 1: i 2 c bus is busy the hbb fag is the i 2 c busy fag. t his fag will be "1" when the i 2 c bus is busy which will occur when a st art signal is detected. the fag will be set to "0" when the bus is free which will occur when a stop signal is detected. bit 4 htx : i 2 c slave device transmitter/receiver selection 0: slave device is the receiver 1: slave device is the transmitter bit 3 txak : i 2 c bus transmit acknowledge fag 0: slave send acknowledge fag 1: slave does not send acknowledge fag the txak bit is the transmit acknowledge fag. after the slave device receipt of 8-bits of data, this bit will be transmitted to the bus on the 9 th clock from the slave device. the slave device must always set txak bit to "0" before further data is received.
rev. 1.40 178 de?e??e? 1?? ?01? rev. 1.40 179 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 2 srw : i 2 c slave read/write fag 0: slave device should be in receive mode 1: slave device should be in transmit mode the sr w f lag i s t he i 2 c sl ave r ead/write f lag. t his f lag d etermines wh ether the master device wishes to transmit or receive data from the i 2 c bus. when the transmitted address and slave address is match, that is when the haas fag is set high, the slave device will check the sr w fag to determine whether it should be in transmit mode or receive mode. if the sr w fag is high, the master is requesting to read data from the bus, so the slave device should be in transmit mode. when the sr w flag is zero, the master will write data to the bus, therefore the slave device should be in receive mode to read this data. bit 1 iamwu : i 2 c address match w ake-up control 0: disable 1: enable C must be cleared by the application program after wake-up this bit should be set to 1 to enabl e the i 2 c address match wake up from the sleep or idle mode. if the iamwu bit has been set before entering either the sleep or idle mode to enable the i 2 c address match wake up, then this bit must be cleared by the application program after wake-up to ensure correction device operation. bit 0 rxak : i 2 c bus receive acknowledge fag 0: slave receives acknowledge fag 1: slave does not receive acknowledge fag the r xak f lag i s t he r eceiver a cknowledge f lag. w hen t he r xak f lag i s "0 ", i t means that a acknowledge signal has been received at the 9 th clock, after 8 bits of data have been transmitted. when the slave device in the transmit mode, the slave device checks the rxak fag to determine if the master receiver wishes to receive the next byte. t he sl ave t ransmitter wi ll t herefore c ontinue se nding out da ta unt il t he rxak fag is "1". when this occurs, the slave transmitter will release the sda line to allow the master to send a stop signal to release the i 2 c bus. i 2 c bus communication communication on the i 2 c bus requires four separate steps, a st art signal, a slave device address transmission, a data transmission and finally a st op signal. when a st art signal is placed on the i 2 c bus, all devices on the bus will receive this signal and be notifed of the imminent arrival of data on the bus. the frst seven bits of the data will be the slave address with the frst bit being the msb. if the address of the slave device matches that of the transmitted address, the haas bit in the simc1 register will be set and an i 2 c interrupt will be generated. after entering the interrupt service routine, the slave device must frst check the condition of the haas and simt of bits to determine whether t he i nterrupt sou rce o riginates fr om a n a ddress m atch, 8 -bit d ata t ransfer c ompletion o r i 2 c bus time-out occurrence. during a data transfer , note that after the 7-bit slave address has been transmitted, the following bit, which is the 8 th bit, is the read/write bit whose value will be placed in the srw bit. this bit will be checked by the slave device to determine whether to go into transmit or receive mode. before any transfer of data to or from the i 2 c bus, the microcontroller must initialise the bus, the following are steps to achieve this: ? step 1 set the sim2~sim 0 bits to "1 10" and simen bit to "1" in the simc0 register to enable the i 2 c bus. ? step 2 write the slave address of the device to the i 2 c bus address register sima. ? step 3 set the sime and sim muti-function interrupt enable bit of the interrupt control register to enable the sim interrupt and multi-function interrupt.
rev. 1.40 180 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 181 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver                       
 
               ?  ?  ?         ?    ?      ?    ? -? ??    ?   ?   ?   ??    -        ? ?    ? -? i 2 c bus initialisation flow chart ? i 2 c bus start signal the st art signal can only be generated by the master device connected to the i 2 c bus and not by the slave device. this st art signal will be detected by all devices connected to the i 2 c bus. when detected, this indicates that the i 2 c bus is busy and therefore the hbb bit will be set. a st art condition occurs when a high to low transition on the sda line takes place when the scl line remains high. ? i 2 c slave address the t ransmission o f a st art si gnal b y t he m aster wi ll b e d etected b y a ll d evices o n t he i 2 c b us. to determine which slave device the master wishes to communicate with, the address of the slave device will be sent out immediately following the st art signal. all slave devices, after receiving this 7-bit address data, will compare it with their own 7-bit slave address. if the address sent out by the maste r matche s the internal address of the microcontroller slave device, then an internal i 2 c bus interrupt signal will be generated. the next bit following the address, which is the 8 th bit, defnes the read/write status and will be saved to the sr w bit of the simc1 register . the slave device will then transmit an acknowledge bit, which is a low level, as the 9 th bit. the slave device will also set the status fag haas when the addresses match. as a n i 2 c bus i nterrupt c an c ome fro m t hree sourc es, whe n t he progra m e nters t he i nterrupt subroutine, the haas and simt of bits should be examined to see whether the interrupt source has come from a matching slave address, the completion of a data byte transfer or the i 2 c bus time-out occurrence. when a slave address is matched, the devices must be placed in either the transmit mode and then write data to the simd register , or in the receive mode where it must implement a dummy read from the simd register to release the scl line.
rev. 1.40 180 de?e??e? 1?? ?01? rev. 1.40 181 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? i 2 c bus read/write signal the sr w bit in the simc1 registe r defnes whether the slave device wishes to read data from the i 2 c bus or write data to the i 2 c bus. the slave device should examine this bit to determine if it is to be a transmitter or a receiver . if the sr w fag is "1" then this indicates that the master device wishes to read data from the i 2 c bus, therefore the slave device must be setup to send data to the i 2 c bus as a transmitter . if the sr w fag is "0" then this indicates that the master wishes to send data to the i 2 c bus, therefore the slave device must be setup to read data from the i 2 c bus as a receiver. ? i 2 c bus slave address acknowledge signal after the mas ter has trans mitted a calling addres s, any s lave device on the i 2 c bus , w hose own internal address matches the calling address, must generate an acknowledge signal. the acknowledge signal will inform the master that a slave device has accepted its calling address. if no acknowledge signal is received by the master then a st op signal must be transmitted by the master to end the communication. when the haas fag is high, the addresses have matched and the slave device must check the sr w fag to determine if it is to be a transmitter or a receiver . if the sr w fag is high, the slave device should be setup to be a transmitter so the htx bit in the simc1 register should be set to "1". if the sr w fag is low , then the microcontroller slave device should be setup as a receiver and the htx bit in the simc1 register should be set to "0". ? i 2 c bus data and acknowledge signal the transmitted data is 8-bits wide and is transmitted after the slave device has acknowledged receipt o f i ts sl ave a ddress. t he o rder o f se rial b it t ransmission i s t he msb fr st a nd t he l sb l ast. after receipt of 8-bits of data, the receiver must transmit an acknowledge signal, level "0", before it can receive the next data byte. if the slave transmitter does not recei ve an acknowledge bit signal from the master receiver , then the slave transmitter will release the sda line to allow the master to send a st op signal to release the i 2 c bus. the corresponding data will be stored in the simd register. if setup as a transmitter , the slave device must frst write the data to be transmitted into the simd register . if setup as a receive r, the slave device must read the transmitted data from the simd register. when the slave receiver receives the data byte, it must generate an acknowledge bit, known as txak, on the 9 th clock. the slave device, which is setup as a transmi tter will check the rxak bit in the simc1 register to determine if it is to send another data byte, if not then it will release the sda line and await the receipt of a stop signal from the master.
rev. 1.40 18 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 183 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver                                 
                                   ?   ?    ?   ? ? ?  ?         ? -      ?      
     -  ?                  ? note: * when a slave address is matched, the device must be placed in either the transmit mode and then write data to the simd register , or in the receive mode where it must implement a dummy read from the simd register to release the scl line. i 2 c communication timing diagram                       
                ?
?   
                                                               ?
?   
                        ??          ?     ??   i 2 c bus isr flow chart
rev. 1.40 18? de?e??e? 1?? ?01? rev. 1.40 183 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver i 2 c time-out control in order to reduce the i 2 c lockup problem due to reception of erroneous clock s ources, a time-out function is provided. if the clock source connected to the i 2 c bus is not received for a while, then the i 2 c circuitry and registers will be reset after a certain time-out period. the time-out counter starts to count on an i 2 c bus "st art" & "address match"c ondition, and is cleared by an scl falling edge. before the next scl falling edge arrives, if the time elapsed is greater than the time-out period specifed by the simt oc register , then a time-out condition will occur . the time-out function will stop when an i 2 c "stop" condition occurs.                                            
         
         i 2 c time-out when an i 2 c time-out counter overfow occurs, the counter will stop and the simt oen bit will be c leared t o z ero a nd t he simt of bi t wi ll be se t hi gh t o i ndicate t hat a t ime-out c ondition ha s occurred. the time-out condition will also generate an interrupt which uses the i 2 c interrrupt vector . when an i 2 c time-out occurs, the i 2 c internal circuitry will be reset and the registers will be reset into the following condition: register after i 2 c time-out simd ? sima ? simc0 no ? hange simc1 reset to por ? ondition i 2 c register after time-out the simtof fag can be cleared by the application program. there are 64 time-out period selections which can be selected using the simt os bits in the simt oc register . the time-out duration is calculated by the formula: ((1~64) (32/f sub )). this gives a time-out period which ranges from about 1ms to 64ms.
rev. 1.40 184 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 18? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ? simtoc register bit 7 6 5 4 3 2 1 0 na ? e simtoen simtof simtos ? simtos4 simtos3 simtos ? simtos1 simtos0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7 simtoen : sim i 2 c t ime-out control 0: disable 1: enable bit 6 simtof : sim i 2 c t ime-out fag 0: no time-out occurred 1: t ime-out occurred bit 5~0 simtos5~simtos0 : sim i 2 c t ime-out period selection i 2 c t ime-out clock source is f sub /32 i 2 c t ime-out period is equal to [ ] ( ) sub f 32 10:5 simtos + uart interface these devices contain an integrated full-duplex asynchronous serial communications uar t interface t hat e nables c ommunication wi th e xternal de vices t hat c ontain a se rial i nterface. t he uart function has many features and can transmit and receive data serially by transferring a frame of data with eight or nine data bits per transmission as well as being able to detect errors when the data is overwri tten or i ncorrectly fra med. the uar t funct ion possesse s it s own i nternal int errupt which can be used to indicate when a reception occurs or when a transmission terminates. the integrated uart function contains the following features: ? full-duplex, asynchronous communication ? 8 or 9 bits character length ? even, odd or no parity options ? one or two stop bits ? baud rate generator with 8-bit prescaler ? parity, framing, noise and overrun error detection ? support for interrupt on address detect (last character bit=1) ? separately enabled transmitter and receiver ? 2-byte deep fifo receive data buffer ? rx pin wake-up function ? t ransmit and receive interrupts ? interrupts can be initialized by the following conditions: transmitter empty transmitter idle receiver full receiver overrun address mode detect
rev. 1.40 184 de?e??e? 1?? ?01? rev. 1.40 18 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver msb lsb ?????????? t?ans?itte? shift registe? ( tsr ) msb lsb ?????????? re?eive? shift registe? ( rsr ) tx pin rx pin baud rate gene?ato? tx registe? ( txr ) rx registe? ( rxr ) data to ?e t?ans?itted data ?e?eived buffe? f sys mcu data bus uart data transfer block diagram uart external pin to communicate with an external serial interface, the internal uar t has two external pins known as tx and rx. the tx and rx pins are the uar t transmitter and receiver pins respectively . the tx and rx pin function should frst be selected by the corresponding pin-shared function selection register before the uar t function is used. along with the uar ten bit, the txen and rxen bits, if set, will automatically setup these i/o or other pin-shared functional pins to their respective tx output a nd rx i nput c onditions a nd di sable a ny pu ll-high re sistor op tion whi ch m ay e xist on t he tx and rx pins. when the tx or rx pin function is disabled by clearing the uar ten, txen or rxen b it, t he t x o r r x p in wi ll b e se t t o a fo ating st ate. at t his t ime wh ether t he i nternal p ull- high resistor is connected to the tx or rx pin or not is determined by the corresponding i/o pull- high function control bit. uart data transfer scheme the a bove di agram shows t he ove rall da ta t ransfer st ructure a rrangement for t he uar t i nterface. the a ctual da ta t o be t ransmitted from t he mcu i s fi rst t ransferred t o t he t xr re gister by t he application program. the data will then be transferred to the t ransmit shift register from where it will be shifted out, lsb frst, onto the tx pin at a rate controlled by the baud rate generator . only the txr register is mapped onto the mcu data memory , the transmit shift register is not mapped and is therefore inaccessible to the application program. data to be received by the uar t is accepted on the external rx pin, from where it is shifted in, lsb fi rst, t o t he re ceiver shi ft re gister a t a ra te c ontrolled by t he ba ud ra te ge nerator. w hen the shift register is full, the data will then be transferred from the shift register to the internal rxr register, where it is buf fered and can be manipulated by the application program. only the txr register i s m apped ont o t he mcu dat a me mory, t he re ceiver shi ft re gister i s not m apped a nd i s therefore inaccessible to the application program. it should be noted that the actual register for data transmission and reception, although referred to in the text, and in application programs, as separate txr and rxr registers, only exists as a single shared register in the data memory . this shared register known as the txr_rxr register is used for both data transmission and data reception. uart status and control registers there are fve control registers associated with the uar t function. the usr, ucr1 and ucr2 registers c ontrol t he o verall f unction o f t he uar t, wh ile t he b rg r egister c ontrols t he b aud r ate. the actua l data to be transmitted and received on the serial interface is managed through the txr_ rxr data registers.
rev. 1.40 18 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 187 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver txr_rxr register the txr_rxr register is the data register which is used to store the data to be transmitted on the tx pin or being received from the rx pin. bit 7 6 5 4 3 2 1 0 na ? e txrx7 txrx ? txrx ? txrx4 txrx3 txrx ? txrx1 txrx0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por x x x x x x x x "x": unknown bit 7~0 txrx7~txrx0 : uart transmit/receive data bits usr register the usr r egister i s t he st atus r egister f or t he uar t, wh ich c an b e r ead b y t he p rogram t o determine the present status of the uar t. all fags within the usr register are read only and further explanations are given below. bit 7 6 5 4 3 2 1 0 na ? e perr nf ferr oerr ridle rxif tidle txif r/w r r r r r r r r por 0 0 0 0 1 0 1 1 bit 7 perr : parity error fag 0: no parity error is detected 1: parity error is detected the perr fag is the parity error fag. when this read only fag is "0", it indicates a parity error has not been detected. when the fag is "1", it indicates that the parity of the received word is incorrect. this error fag is applicable only if parity mode (odd or even) is selected. the fag can also be cleared by a software sequence which involves a read to the status register usr followed by an access to the rxr data register. bit 6 nf : noise fag 0: no noise is detected 1: noise is detected the nf fla g is the noise fla g. whe n thi s read only fla g is "0", it indi cates no noise condition. when the fag is "1", it indicates that the uar t has detected noise on the receiver input. the nf fag is set during the same cycle as the rxif fag but will not be set in the case of as overrun. the n f fag can be cleared by a softw are sequence which will involve a read to the status register usr followed by an access to the rxr data register. bit 5 ferr : framing error fag 0: no framing error is detected 1: framing error is detected the ferr fag is the framing error fag. when this read only fag is "0", it indicates that there is no framing error . when the fag is " 1", it indicates that a framing error has been detected for the current character . the fag can also be cleared by a software sequence which will involve a read to the status register usr followed by an access to the rxr data register. bit 4 oerr : overrun error fag 0: no overrun error is detected 1: overrun error is detected the oerr fag is the overrun error fag which indicates when the rece iver buf fer has overfowed. when this read only fag is "0", it indicates that there is no overrun error . when the fag is "1", it indicates that an overrun error occurs which will inhibit further transfers to the rxr receive data register . the fag is cleared by a software sequence, which is a read to the s tatus regis ter u sr follow ed by an acces s to the rx r data register.
rev. 1.40 18? de?e??e? 1?? ?01? rev. 1.40 187 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 3 ridle : receiver status 0: data reception is in progress (data being received) 1: no data reception is in progress (receiver is idle) the ridle fag is the receiver status fag. when this read only fag is "0", it indicates that the receiver is between the init ial detection of the start bit and the completion of the stop bit. when the fag is "1", it indicates that the receiver is idle. between the completion of the stop bit and the detection of the next start bit, the ridle bit is "1" indicating that the uart receiver is idle and the rx pin stays in logic high condition. bit 2 rxif : receive rxr data register status 0: rxr data register is empty 1: rxr data register has available data the rxif fag is the receive data register status fag. when this read only fag is "0", it indicates that the rxr read data register is empty . when the fag is "1", it indicates that t he r xr r ead d ata r egister c ontains n ew d ata. w hen t he c ontents o f t he sh ift register are trans ferred to the rx r register , an interrupt is generated if rie=1 in the ucr2 register . if one or more errors are detected in the received word, the appropriate receive-related fags nf , ferr, and/or perr are set within the same clock cycle. the rxif fag is clear ed when the usr register is read with rxif set, followed by a read from the rxr register, and if the rxr register has no data available. bit 1 tidle : t ransmission status 0: data transmission is in progress (data being transmitted) 1: no data transmission is in progress (transmitter is idle) the tidle flag is known as the transmission complete flag. when this read only fag is "0", it indicates that a transmission is in progress. this fag will be set to "1" when the txif fag is "1" and when there is no transmit data or break character being transmitted. when tidle is equal to 1, the tx pin becomes idle with the pin state in logic high condition. the tidle fag is cleared by reading the usr register with tidle set and then writing to the txr register . the fag is not generated when a data character or a break is queued and ready to be sent. bit 0 txif : t ransmit txr data register status 0: character is not transferred to the transmit shift register 1: character has transferred to the transmit shift register (txr data register is empty) the txif fag is the transmit data register empty fag. when this read only fag is "0", it indicat es that the character is not transferred to the transmitter shift register . when the fag is "1", it indicates that the transmitter shift register has received a character from the txr data register . the txif flag is cleared by reading the uar t status register (usr) with txif set and then writing to the txr data register . note that when t he t xen b it i s se t, t he t xif fa g b it wi ll a lso b e se t si nce t he t ransmit d ata register is not yet full.
rev. 1.40 188 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 189 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver ucr1 register the ucr1 register together with the ucr2 register are the uar t control registers that are used to set the various options for the uar t function such as overall on/of f control, parity control, data transfer bit length, etc. further explanation on each of the bits is given below. bit 7 6 5 4 3 2 1 0 na ? e uarten bno pren prt stops txbrk rx8 tx8 r/w r/w r/w r/w r/w r/w r/w r w por 0 0 0 0 0 0 x 0 "x": unknown bit 7 uarten : uart function enable control 0: disable uart; tx and rx pins are in a foating state. 1: enable uart; tx and rx pins function as uart pins the uar ten bit is the uar t enable bit. when this bit is equal to "0", the uar t will be disabled and the rx pin as well as the tx pin will be set in a foating state. when the bit is equal to "1", the uar t will be enabled and the tx and rx pins will function as defined by the txen and rxen enable control bits. when the uar t is disabled, it will empty the buf fer so any character remaining in the buf fer will be discarded. in addition, the value of the baud rate counter will be reset. if the uar t is disabled, all error and status fags will be reset. also the txen, rxen, txbrk, rxif, oerr, ferr, perr and nf bits will be cleared, while the tidle, txif and ridle bits will be set. other control bits in ucr1, ucr2 and brg registers will remain unaf fected. if the uar t is active and the uar ten bit is clear ed, all pending transmissions and re ceptions wi ll be terminated a nd t he module will be reset as defned above. when the uart is re-enabled, it will restart in the same confguration. bit 6 bno : number of data transfer bits selection 0: 8-bit data transfer 1: 9-bit data transfer this bit is used to select the data length format, which can have a choice of either 8-bit or 9-bit format. when this bit is equal to "1", a 9-bit data length format will be selected. if the bit is equal to "0", then an 8-bit data length format will be selected. if 9-bit data length format is selected, then bits rx8 and tx8 will be used to store the 9th bit of the received and transmitted data respectively. bit 5 pren : parity function enable control 0: parity function is disabled 1: parity function is enabled this bit is the parity function enable bit. when this bit is equal to 1, the parity function will be enabled. if the bit is equal to 0, then the parity function will be disabled. bit 4 prt : parity type selection bit 0: even parity for parity generator 1: odd parity for parity generator this bit is the parity type selection bit. when this bit is equal to 1, odd parity type will be selected. if the bit is equal to 0, then even parity type will be selected. bit 3 stops : number of stop bits selection 0: one stop bit format is used 1: t wo stop bits format is used this bit determines if one or two stop bits are to be used. when this bit is equal to "1", two stop bits format are used. if the bit is equal to "0", then only one stop bit format is used. bit 2 txbrk : transmit break character 0: no break character is transmitted 1: break characters transmit the t xbrk bi t i s t he t ransmit bre ak cha racter bi t. w hen t his bi t i s e qual t o "0", there are no break characters and the tx pin operats normally . when the bit is equal to "1", there are transmit break characters and the transmitter will send logic zeros. when this bit is equal to "1", after the buf fered data has been transmitted, the transmitter output is held low for a minimum of a 13-bit length and until the txbrk bit is reset.
rev. 1.40 188 de?e??e? 1?? ?01? rev. 1.40 189 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 1 rx8 : receive data bit 8 for 9-bit data transfer format (read only) this bit is only used if 9-bit data transfers are used, in which case this bit location will store the 9 th bit of the receive d data known as rx8. the bno bit is used to determ ine whether data transfes are in 8-bit or 9-bit format. bit 0 tx8 : transmit data bit 8 for 9-bit data transfer format (write only) this bit is only us ed if 9-bit data transfers are us ed, in w hich cas e this bit location will store the 9 th bit of the transmitted data known as tx8. the bno bit is used to determine whether data transfes are in 8-bit or 9-bit format. ucr2 register the ucr2 register is the second of the uar t control registers and serves several purposes. one of its main functions is to control the basic enable/disable operation if the uar t t ransmitter and receiver as well as enabling the various uar t interrupt sources. the register also serves to control the baud rate speed, receiver wake-up function enable and the address detect function enable. further explanation on each of the bits is given below. bit 7 6 5 4 3 2 1 0 na ? e txen rxen brgh adden wake rie tiie teie r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7 txen : uart t ransmitter enable control 0: uart t ransmitter is disabled 1: uart t ransmitter is enabled the txen bit is the t ransmitter enable bit. when this bit is equal to "0", the transmitter will be disabled with any pending data transmissions being aborted. in addition the buf fers will be reset. in this situation the tx pin will be set in a foating state. i f t he t xen b it i s e qual t o "1 " a nd t he uar ten b it i s a lso e qual t o 1 , t he transmitter will be enabled and the tx pin will be controlled by the uar t. clearing the txen bit during a transmission will cause the data transmission to be aborted and will reset the transmitter . if this situation occurs, the tx pin will be set in a foating state. bit 6 rxen : uart receiver enable control 0: uart receiver is disabled 1: uart receiver is enabled the rxen bit is the receiver enable bit. when this bit is equal to "0", the receiver will be disabled with any pending data receptions being aborted. in addition the receiver buf fers will be reset. in this situation the rx pin will be set in a foating state. if the rxen bit is equal to "1" and the uar ten bit is also equal to 1, the receiver will be enabled and the rx pin will be controlled by the uar t. clea ring the rxen bit during a reception will cause the data reception to be aborted and will reset the receiver. if this situation occurs, the rx pin will be set in a foating state. bit 5 brgh : baud rate speed selection 0: low speed baud rate 1: high speed baud rate the bit named brgh selects the high or low speed mode of the baud rate generator . this bit, together w ith the value placed in the baud rate regis ter, brg , controls the baud rate of the uart. if the bit is equal to 0, the low speed mode is selected.
rev. 1.40 190 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 191 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 4 adden : address detect function enable control 0: address detection function is disabled 1: address detection function is enabled the bit named adden is the address detection function enable control bit. when this bit is equal to 1, the address detection function is enabled. when it occurs, if the 8 th bit, which corresponds to rx7 if bno=0, or the 9 th bit, which corresponds to rx8 if bno=1, ha s a va lue of "1 ", t hen t he re ceived word wi ll be i dentifed a s a n a ddress, rather than data. if the corresponding interrupt is enabled, an interrupt request will be generated each time the received word has the address bit set, which is the 8 th or 9 th bit depending on the value of the bno bit. if the address bit known as the 8 th or 9 th bit of the received word is "0" with the address detection function being enabled, an interrupt will not be generated and the received data will be discarded. bit 3 wake : rx pin falling edge wake-up function enable control 0: rx pin wake-up function is disabled 1: rx pin wake-up function is enabled the bit enables or disables the rece iver wake-up function. if this bit is equal to 1 and the device is in idle0 or sleep mode, a falling edge on the rx pin will wake up the device. if this bit is equal to 0 and the device is in idle or sleep mode, any edge transitions on the rx pin will not wake up the device. bit 2 rie : receiver interrupt enable control 0: receiver related interrupt is disabled 1: receiver related interrupt is enabled the bit enables or disables the rece iver interrupt. if this bit is equal to 1 and when the receiver overrun flag oerr or received data available flag rxif is set, the uar t interrupt request fag will be set. if this bit is equal to 0, the uar t interrupt request fag will not be infuenced by the condition of the oerr or rxif fags. bit 1 tiie : transmitter idle interrupt enable control 0: t ransmitter idle interrupt is disabled 1: t ransmitter idle interrupt is enabled the bit enables or disables the transmitter idle interrupt. if this bit is equal to 1 and when t he t ransmitter i dle fa g t idle i s se t, due t o a t ransmitter i dle c ondition, t he uart interrupt request fag will be set. if this bit is equal to 0, the uar t interrupt request fag will not be infuenced by the condition of the tidle fag. bit 0 teie : transmitter empty interrupt enable control 0: t ransmitter empty interrupt is disabled 1: t ransmitter empty interrupt is enabled the bit enables or disables the transmitter empty interrupt. if this bit is equal to 1 and when the transmit ter empty fag txif is set, due to a transmitter empty condition, the uart interrupt request fag will be set. if this bit is equal to 0, the uar t interrupt request fag will not be infuenced by the condition of the txif fag.
rev. 1.40 190 de?e??e? 1?? ?01? rev. 1.40 191 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver baud rate generator to setup the speed of the serial data communication, the uar t function contains its own dedicated baud ra te ge nerator. t he ba ud ra te i s c ontrolled by i ts own i nternal fre e runni ng 8-bi t t imer, t he period o f wh ich i s d etermined b y t wo f actors. t he f irst o f t hese i s t he v alue p laced i n t he b rg register and the second is the value of the brgh bit within the ucr2 control register . the brgh bit decides, if the baud rate generat or is to be used in a high speed mode or low speed mode, which in turn determines the formula that is used to calculate the baud rate. the value in the brg register , n, which is used in the following baud rate calculation formula determines the division factor . note that n is the decimal value placed in the brg register and has a range of between 0 and 255. ucr2 brgh bit 0 1 baud rate (br) )] 1 n( 64 [ f sys + )] 1 n( 16 [ f sys + by programming the brgh bit which allows selection of the related formula and programming the required value in the brg register , the required baud rate can be setup. note that because the actual baud rate is determ ined using a discrete value, n, placed in the brg register , there will be an error associated between the actual and requested value. the following example shows how the brg register value n and the error value can be calculated. brg register bit 7 6 5 4 3 2 1 0 na ? e brg7 brg ? brg ? brg4 brg3 brg ? brg1 brg0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por x x x x x x x x "x": unknown bit 7~0 brg7~brg0 : baud rate values by programming the brgh bit in the ucr2 register which allows selection of the related formula described above and programming the required value in the brg register, the required baud rate can be setup. calculating the baud rate and error values for a clock frequency of 4mhz, and with brgh set to 0 determine the brg register value n, the actual baud rate and the error value for a desired baud rate of 4800. from the above table the desired baud rate br = )] 1 n( 64 [ f sys + ? = 1 ) 64 br ( f sys ? = . 12 1 ) 64 4800 ( 4000000 =? = 1 12 ( 64 [ 4000000 = + ? =
rev. 1.40 19 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 193 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver uart setup and control for data transfer , the uar t functio n utilizes a non-return-to-zero, more commonly known as nrz, format. this is compos ed of one s tart bit, eight or nine data bits and one or two s top bits . p arity is supporte d by t he uar t hardwa re and ca n be se tup t o be eve n, odd or no pari ty. for the m ost common data format, 8 data bits along with no parity and one stop bit, denoted as 8, n, 1, is used as the default setti ng, which is the setting at power -on. the number of data bits and stop bits, along with the parity , are setup by programming the corresponding bno, pr t, pren and st ops bits in the ucr1 register . the baud rate used to transmit and receive data is setup using the internal 8-bit baud rate generator , while the data is transmitted and received lsb frst. although the transmitter and receiver of the uart are functionally independent, they both use the same data format and baud rate. in all cases stop bits will be used for data transmission. enabling/disabling the uart interface the basic on/of f function of the internal uar t function is controlled using the uar ten bit in the ucr1 register . if the uar ten, txen and rxen bits are set, then these two uar t pins will act as n ormal t x o utput p in a nd r x i nput p in r espectively. i f n o d ata i s b eing t ransmitted o n t he t x pin, then it will default to a logic high value. clearing t he uar ten b it wi ll d isable t he t x a nd r x p ins a nd t hese t wo p ins wi ll b e u sed a s a n i/o or other pin-shared functional pin. when the uar t function is disabled, the buf fer will be reset to an empty condition, at the same time discarding any remaining residual data. disabling the uart will also reset the enable control, the error and status fags with bits txen, rxen, txbrk, rxif, oe rr, fe rr, pe rr and nf bei ng c leared whi le bi ts t idle, t xif and ridl e wi ll be set. the remaining control bits in the ucr1, ucr2 and brg registers will remain unaf fected. if the uar ten bit in the ucr1 regi ster is cl eared while the uar t is act ive, then all pendi ng transmissions and receptions will be immediately suspended and the uar t will be reset to a condition as defned above. if the uar t is then subsequently re-enabled, it will restart again in the same confguration. data, parity and stop bit selection the f ormat o f t he d ata t o b e t ransferred i s c omposed o f v arious f actors su ch a s d ata b it l ength, parity on/of f, parity type, address bits and the number of stop bits. these factors are determined by the setup of various bits within the ucr1 register . the bno bit controls the number of data bits which can be set to either 8 or 9. the pr t bit controls the choice if odd or even parity . the pren bit controls the parity on/of f function. the st ops bit decides whether one or two stop bits are to be used. the following table shows various formats for data transmission. the address detect mode control bit identif es the frame as an address character . the number of stop bits, which can be either one or two, is independent of the data length. start bit data bits address bits parity bit stop bit example of 8-bit data formats 1 8 0 0 1 1 7 0 1 1 1 7 1 0 1 example of 9-bit data formats 1 9 0 0 1 1 8 0 1 1 1 8 1 0 1 transmitter receiver data format
rev. 1.40 19? de?e??e? 1?? ?01? rev. 1.40 193 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver the following diagram shows the transmit and receive waveforms for both 8-bit and 9-bit data formats.                                      
  8-bit data format                                    
     9-bit data format uart transmitter data word lengths of either 8 or 9 bits can be selected by programming the bno bit in the ucr1 register. w hen b no b it i s se t, t he wo rd l ength wi ll b e se t t o 9 b its. i n t his c ase t he 9 th b it, wh ich is the msb, needs to be stored in the tx8 bit in the ucr1 register . at the transmitter core lies the transmitter shift register , more commonly known as the tsr, whos e data is obtained from the transmit d ata r egister, wh ich i s k nown a s t he t xr r egister. t he d ata t o b e t ransmitted i s l oaded into this txr register by the applic ation program. the tsr register is not written to with new data until the stop bit from the previous transmission has been sent out. as soon as this stop bit has been transmitted, the tsr can then be loaded with new data from the txr register , if it is available. it should be noted that the tsr register , unlike many other registers, is not directly mapped into the data memory area and as such is not available to the application program for direct read/write operations. an actual transmission of data will normally be enabled when the txen bit is set, but the data will not be transmitted until the txr register has been loaded with data and the baud rate generator ha s de fned a shi ft c lock sourc e. however , t he t ransmission c an a lso be i nitiated by frst loading data into the txr register , after which the txen bit can be set. when a transmission of data begins, the tsr is normally empty , in which case a transfer to the txr register will result in an immed iate transfer to the tsr. if during a transmission the txen bit is cleared, the transmission will imm ediately cease and the transmitter will be reset. the tx output pin will then return to the i/ o or other pin-shared function. transmitting data when the uar t is transmitting data, the data is shifted on the tx pin from the shift register , with the least signifcant bit lsb frst. in the transmit mode, the txr register forms a buf fer between the internal bus and the transmitter shift register . it should be noted that if 9-bit data format has been selected, then the msb will be take n from the tx8 bit in the ucr1 register . the steps to initiate a data transfer can be summarized as follows: ? make the correct selection of the bno, pr t, pren and st ops bits to defne the required word length, parity type and number of stop bits. ? setup the brg register to select the desired baud rate. ? set the txe n bit to ensure that the uar t transmit ter is enabled and the tx pin is used as a uart transmitter pin. ? access the usr register and write the data that is to be transmitted into the txr register . note that this step will clear the txif bit.
rev. 1.40 194 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 19? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver this sequence of events can now be repeated to send additional data. it should be noted that when txif=0, data will be inhibited from being written to the txr register . clearing the txif fag is always achieved using the following software sequence: 1. a usr register access 2. a txr register write execution the read-only txif fag is set by the uar t hardware and if set indic ates that the txr register is empty and that other data can now be written into the txr register without overwriting the previous data. if the teie bit is set, then the txif fag will generate an interrupt. during a data transmission, a write instruction to the txr register will place the data into the txr register , which will be copied to the shift register at the end of the present transmission. when there is no data transmission in progress, a write instruction to the txr register will place the data directly into the shift register , resulting in the commencement of data transmission, and the txif bit being immediately set. when a frame transmission is complete, which happens after stop bits are sent or after the break frame, the tidle bit will be set. t o clear the tidle bit the following software sequence is used: 1. a usr register access 2. a txr register write execution note that both the txif and tidle bits are cleared by the same software sequence. transmitting break if the txbrk bit is set, then the break characters will be sent on the next transmission. break character transmission consists of a start bit, followed by 13xn "0" bits, where n=1, 2, etc. if a break character is to be transmitted, then the txbrk bit must be frst set by the application program and then cleared to generate the stop bits. t ransmitting a break character will not generate a transmit interrupt. note that a break condition length is at least 13 bits long. if the txbrk bit is continually kept a t a l ogic hi gh l evel, t hen t he t ransmitter c ircuitry wi ll t ransmit c ontinuous bre ak c haracters. after the application program has cleared the txbrk bit, the transmitter will fnish transmitting the last break character and subsequently send out one or two stop bits. the automatic logic high at the end of the last break character will ensure that the start bit of the next frame is recognized. uart receiver the uart is capable of receiving word lengths of either 8 or 9 bits can be selected by programming the bno bit in the ucr1 register . when bno bit is set, the word length will be set to 9 bits. in this c ase t he 9 th b it, wh ich i s t he msb , wi ll b e st ored i n t he r x8 b it i n t he uc r1 r egister. at t he receiver core lies the receiver shift register more commonly known as the rsr. the data which is receive d on the rx external input pin is sent to the data recovery block. the data recovery block operating speed is 16 times that of the baud rate, while the main receiv e serial shifter operates at the baud rate. after the rx pin is sampled for the stop bit, the received data in rsr is transferred to the receive data register, if the register is empty. the data which is received on the external rx input pin is sample d three times by a majority detect circuit to determine the logic level that has been placed onto the rx pin. it should be noted that the rsr register , unlike many other registers, is not directly mapped into the data memory area and as such is not available to the application program for direct read/write operations.
rev. 1.40 194 de?e??e? 1?? ?01? rev. 1.40 19 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver receiving data when the uar t receiver is receiv ing data, the data is serially shifted in on the external rx input pin to the shift register , with the lea st signifcant bit lsb frst. the rxr register is a two byte deep fifo data buf fer, w here tw o bytes can be held in the f ifo w hile the 3 rd byte can continue to be received. note that the application program must ensure that the data is read from rxr before the 3 rd byte has been completely shifted in, otherwise the 3 rd byte will be discarded and an overrun error oerr will be subsequently indicated. the steps to initiate a data transfer can be summarized as follows: ? make the correct selection of the bno, pr t, pren and st ops bits to defne the required word length, parity type and number of stop bits. ? setup the brg register to select the desired baud rate. ? set the rxen bit to ensure that the uar t receiver is enabled and the rx pin is used as a uar t receiver pin. at this point the receiver will be enabled which will begin to look for a start bit. when a character is received, the following sequence of events will occur: ? the rxif bit in the usr register will be set then rxr register has data available, at least one more character can be read. ? when the content s of the shift register have been transferred to the rxr register and if the rie bit is set, then an interrupt will be generated. ? if during reception, a frame error , noise error , parity error or an overrun error has been detected, then the error fags can be set. the rxif bit can be cleared using the following software sequence: 1. a usr register access 2. a rxr register read execution receiving break any break character received by the uar t will be managed as a framing error . the receiver will count and expect a certain number of bit times as specifed by the value s programmed into the bno and st ops bits. if the break is much longer than 13 bit times, the reception will be considered as complete a fter t he num ber of bi t t imes spe cifed by bno a nd st ops. t he rxif bi t i s se t, fe rr is set, zeros are loaded into the rece ive data register , interrupts are generated if appropriate and the ridle bit is set. if a long break signal has been detected and the receiver has received a start bit, the data bits and the invalid stop bit, which sets the ferr fag, the receiver must wait for a valid stop bit before looking for the next start bit. the receiver will not make the ass umption that the break condition on the line is the next start bit. a break is regarded as a character that contains only zeros with the ferr fag set. the break character will be loaded into the buf fer and no further data will be received until stop bits are received. it should be noted that the ridle read only fag will go high when the stop bits have not yet been received. the reception of a break character on the uar t registers will result in the following: ? the framing error fag, ferr, will be set. ? the receive data register, rxr, will be cleared. ? the oerr, nf, perr, ridle or rxif fags will possibly be set.
rev. 1.40 19 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 197 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver idle status when the receiver is reading data, which means it will be in between the detection of a start bit and the readin g of a stop bit, the receiver status fag in the usr register , otherwise known as the ridle fag, will have a zero value. in between the reception of a stop bit and the detection of the next start bit, the ridle fag will have a high value, which indicates the receiver is in an idle condition. receiver interrupt the read only receive interrupt flag, rxif , in the usr register is set by an edge generated by the receiver. an interrupt is generated if rie=1, when a word is transferred from the receive shift register , rsr, to the receive data register, rxr. an overrun error can also generate an interrupt if rie=1. managing receiver errors several types of reception errors can occur within the uart module, the following section describes the various types and how they are managed by the uart. overrun error C oerr the rxr register is composed of a two byte deep fifo data buf fer, where two bytes can be held in the fifo register , while a 3 th byte can continue to be received. before the 3 th byte has been entirely shifted in, the data should be read from the rxr register . if this is not done, the overrun error fag oerr will be consequently indicated. in the event of an overrun error occurring, the following will happen: ? the oerr fag in the usr register will be set. ? the rxr contents will not be lost. ? the shift register will be overwritten. ? an interrupt will be generated if the rie bit is set. the o err flag can be cleared by an acces s to the u sr regis ter follow ed by a read to the rx r register. noise error C nf over-sampling i s u sed f or d ata r ecovery t o i dentify v alid i ncoming d ata a nd n oise. i f n oise i s detected within a frame, the following will occur: ? the read only noise fag, nf, in the usr register will be set on the rising edge of the rxif bit. ? data will be transferred from the shift register to the rxr register. ? no interrupt will be generated. however this bit rises at the same time as the rxif bit which itself generates an interrupt. note t hat t he nf fa g i s r eset b y a usr r egister r ead o peration f ollowed b y a n r xr r egister r ead operation. framing error C ferr the read only framing error fag, ferr, in the usr register , is set if a zero is detected instead of stop bits. if two stop bits are selecte d, both stop bits must be high. otherwise the ferr fag will be set. the ferr fag is buffered along with the received data and is cleared in any reset. parity error C perr the read only parity error fag, perr, in the usr register , is set if the parity of the received word is incorrect. this error fag is only applicable if the parity function is enabled, pren=1, and if the parity type, odd or even, is s elected. the read only p err f ag is buf fered along w ith the received data bytes. it is cleared on any reset, it should be noted that the ferr and perr fags are buf fered along with the corresponding word and should be read before reading the data word.
rev. 1.40 19? de?e??e? 1?? ?01? rev. 1.40 197 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver uart interrupt structure several i ndividual uar t c onditions c an ge nerate a uar t i nterrupt. w hen t hese c onditions e xist, a low pulse will be generated to get the attention of the microcontroller . these conditions are a transmitter data register empty , trans mitter idle, receiver data available, receiver overrun, addres s detect and an rx pin wake-up. when any of these conditions are created, if its corresponding interrupt cont rol is enabled and the stac k is not ful l, the progra m wil l jump to it s corresponding interrupt vector w here it can be serviced before returning to the main program. four of thes e conditions h ave t he c orresponding usr r egister fa gs wh ich wi ll g enerate a uar t i nterrupt i f i ts associated interrupt enable control bit in the ucr2 register is set. the two transmitter interrupt conditions have their own corresponding enable control bits, while the two receiver interrupt conditions have a shared enable control bit. these enable bits can be used to mask out individual uart interrupt sources. the address det ect condit ion, whi ch i s al so a uar t i nterrupt source, does not have an associa ted flag, but will generate a uar t interrupt when an address detect condition occurs if its function is e nabled by se tting t he adde n bi t i n t he ucr2 re gister. an rx pi n wa ke-up, whi ch i s a lso a uart interrupt source, does not have an associated fag, but will generate a uar t interrupt if the microcontroller i s woke n up from idle0 or sl eep m ode by a fa lling e dge on t he rx pi n, i f t he wake and rie bits in the ucr2 register are set. note that in the event of an rx wake-up interrupt occurring, there will be a certain period of delay , commonly known as the system start-up t ime, for the oscillator to restart and stabilize before the system resumes normal operation. note t hat t he usr r egister f lags a re r ead o nly a nd c annot b e c leared o r se t b y t he a pplication program, neither will they be cleared when the program jumps to the corresponding interrupt servicing routine, as is the cas e for some of the other interrupts. the flags will be cleared automatically whe n c ertain a ctions a re t aken by t he uar t, t he de tails of whi ch a re gi ven i n t he uart regi ster se ction. the overal l uar t i nterrupt ca n be disable d or ena bled by t he rel ated interrupt enable control bits in the interrupt control registers of the microcontroller to decide whether the interrupt requested by the uart module is masked out or allowed. usr registe? t?ans?itte? e?pty flag txif 0 1 wake inte??upt signal to mcu t?ans?itte? idle flag tidle re?eive? ove??un flag oerr re?eive? data availa?le rxif rx pin wake - up ucr ? registe? or 0 1 adden 0 1 rie 0 1 tiie 0 1 teie 0 1 rx 7 if bno =0 rx 8 if bno =1 ucr ? registe? uart inte??upt request flag urf 0 1 ure 0 1 emi uart interrupt structure
rev. 1.40 198 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 199 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver address detect mode setting the address detect function enable control bit, adden, in the ucr2 register , enables this special function. if this bit is set to 1, then an additional qualifer will be placed on the generation of a re ceiver da ta a vailable i nterrupt, whi ch i s re quested by t he rxif fl ag. if t he adde n bi t is equal to 1, then w hen the data is available, an interrupt w ill only be generated, if the highest received bit has a high value. note that the related interrupt enable control bit and the emi bit of the microcontroller must also be enabled for correct interrupt generation. the highest address bit is the 9 th bit if the bit bno=1 or the 8 th bit if the bit bno=0. if the highest bit is high, then the received word wi ll be de fned a s a n a ddress ra ther t han da ta. a da ta a vailable i nterrupt wi ll be ge nerated every tim e the last bit of the receiv ed word is set. if the adden bit is equal to 0, then a receive data a vailable interrupt will be generated each time the rxif fag is set, irrespective of the data last but status. the address detection and parity functions are mutually exclusive functions. therefore, if the address detect function is enable d, then to ensure correct operation, the parity function should be disabled by resetting the parity function enable bit pren to zero. adden bit 9 if bno=1 bit 8 if bno=0 uart interrupt generated 0 0 1 1 0 x 1 adden bit function uart power down and wake-up when the mcu system clock is switched of f, the uar t will cease to function. if the mcu executes the "hal t" instruction and switches of f the system clock while a transmission is still in progress, then the transmission will be paused until the uar t clock source derived from the microcontroller is activated. in a similar way , if the mcu executes the "hal t" instruction and switches of f the system clock w hile receiving data, then the reception of data w ill likewise be paus ed. when the mcu enters the idle or sleep mode, note that the usr, ucr1, ucr2, transmit and receive registers, as well as the brg register will not be af fected. it is recomm ended to make sure frst that the uar t data transmission or reception has been finished before the microcontroller enters the idle or sleep mode. the ua rt function contains a receiver rx pin wake-up function, which is enabled or disabled by the w ake bit in the ucr2 register . if this bit, along with the uar t enable bit, uar ten, the receiver enable bit, rxen and the receiver interrupt bit, rie, are all set before the mcu enters the idle0 or sleep mode, then a fall ing edge on the rx pin will wake up the mcu from the idle0 or sl eep mo de. no te t hat a s i t t akes c ertain sy stem c lock c ycles a fter a wa ke-up, b efore n ormal microcontroller operation resumes, any data received during this time on the rx pin will be ignored. for a uar t wake-up interrupt to occur , in addition to the bits for the wake-up being set, the global interrupt enable bit, emi, and the uart interrupt enable bit, ure, must be set. if the emi and ure bits are not set then only a wake up event will occur and no interrupt will be generated. note also that as it takes certain system clock cycles after a wake-up before normal microcontroller resumes, the uart interrupt will not be generated until after this time has elapsed.
rev. 1.40 198 de?e??e? 1?? ?01? rev. 1.40 199 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver touch key function each device provides multiple touch key functions. the touch key function is fully integrated and requires no external components, allowing touch key functions to be implemented by the simple manipulation of internal registers. touch key structure the touch keys are pin shared with the i/o pins, with the desired function chosen via the pin-shared selection register bit. keys are or ganised into several groups, with eac h group known as a module and having a module number , m0 to mn. each module is a fully indepe ndent set of four t ouch keys and each t ouch key has its own oscillator . each module contains its own control logic circuits and register set. examination of the register names will reveal the module number it is referring to. device total key number touch key module touch key bs ?? f370 3 ? m0 key1~key4 m1 key ? ~key8 m ? key9~key1 ? m3 key13~key1 ? m4 key17~key ? 0 m ? key ? 1~key ? 4 m ? key ?? ~key ? 8 m7 key ? 9~key3 ? m8 key33~key3 ? bs ?? f3 ? 0 ? 8 m0 key1~key4 m1 key ? ~key8 m ? key9~key1 ? m3 key13~key1 ? m4 key17~key ? 0 m ? key ? 1~key ? 4 m ? key ?? ~key ? 8 bs ?? f3 ? 0 ? 0 m0 key1~key4 m1 key ? ~key8 m ? key9~key1 ? m3 key13~key1 ? m4 key17~key ? 0 bs ?? f340 1 ? m0 key1~key4 m1 key ? ~key8 m ? key9~key1 ? touch key structure
rev. 1.40 ? 00 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?01 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver key 1 key osc key ? key osc key 3 key osc key 4 key osc tkrcov multi - f?equen?y mndfen tkmn 1? dh / tkmn 1?dl ( to data me?o?y se?to? ?) tkcfov tk 1? dl / tk 1? dh mux . module 0 tktmr refe?en?e os?illato? tkmnroh / tkmnrol ( f?o? data me?o?y se?to? ?) filte? module n 1? - ?it c / f counte? filte? f sys /4 m u x mntss tkmnc ? 8- ?it ti?e slot counte? ?- ?it unit pe?iod ?ounte? 8- ?it ti?e slot counte? p?eload registe? tktmr ove?flow 1? - ?it counte? tk 1? ov m u x tk 1? s1~ tk 1? s0 f sys /4 f sys /? f sys f sys /8 1? - ?it c / f counte? value ( se?to? ?) tou?h key data me?o?y refe?en?e os? . capa?ito? value ( se?to? ?) note: the structure contained in the dash line is identical for each touch key module which contains four touch keys. touch key function block diagram touch key register defnition each t ouch k ey m odule, wh ich c ontains f our t ouch k ey f unctions, h as i ts o wn su ite r egisters. t he following table shows the register set for each touch key module. the mn within the register name refers to the t ouch key module number . the series of devices has up to seven t ouch key modules dependent upon the selected device. name description tktmr tou ? h key ti ? e slot 8- ? it ? ounte ? p ? oload ? egiste ? tkc0 tou ? h key fun ? tion cont ? ol ? egiste ? 0 tkc1 tou ? h key fun ? tion cont ? ol ? egiste ? 1 tk1 ? dl tou ? h key fun ? tion 1 ? - ? it ? ounte ? low ? yte tk1 ? dh tou ? h key fun ? tion 1 ? - ? it ? ounte ? high ? yte tkmn1 ? dl tou ? h key ? odule n 1 ? - ? it c/f ? ounte ? low ? yte tkmn1 ? dh tou ? h key ? odule n 1 ? - ? it c/f ? ounte ? high ? yte tkmnrol tou ? h key ? odule n ? efe ? en ? e os ? illato ? ? apa ? ito ? sele ? t low ? yte tkmnroh tou ? h key ? odule n ? efe ? en ? e os ? illato ? ? apa ? ito ? sele ? t high ? yte tkmnc0 tou ? h key ? odule n cont ? ol ? egiste ? 0 tkmnc1 tou ? h key ? odule n cont ? ol ? egiste ? 1 tkmnc ? tou ? h key ? odule n cont ? ol ? egiste ? ? touch key module registers list
rev. 1.40 ?00 de?e??e? 1?? ?01? rev. 1.40 ? 01 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver register name bit 7 6 5 4 3 2 1 0 tktmr d7 d ? d ? d4 d3 d ? d1 d0 tkc0 tkramc tkrcov tkst tkcfov tk1 ? ov tkmod tkbusy tkc1 d7 d ? d ? tscs tk1 ? s1 tk1 ? s0 tkfs1 tkfs0 tk1 ? dl d7 d ? d ? d4 d3 d ? d1 d0 tk1 ? dh d1 ? d14 d13 d1 ? d11 d10 d9 d8 tkmn1 ? dl d7 d ? d ? d4 d3 d ? d1 d0 tkmn1 ? dh d1 ? d14 d13 d1 ? d11 d10 d9 d8 tkmnrol d7 d ? d ? d4 d3 d ? d1 d0 tkmnroh d9 d8 tkmnc0 mndfen d4 mnsofc mnsof ? mnsof1 mnsof0 tkmnc1 mntss mnroen mnkoen mnk4en mnk3en mnk ? en mnk1en tkmnc ? mnsk31 mnsk30 mnsk ? 1 mnsk ? 0 mnsk11 mnsk10 mnsk01 mnsk00 touch key function registers list tktmr register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? d4 d3 d ? d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7~0 d7~d0 : t ouch key time slot 8-bit counter proload register the touch key time slot counter proload register is used to determine the touch key time slot overfow time. the time slot unit period is obtained by a 5-bit counter and equal t o 32 t ime sl ot c lock c ycles. t herefore, t he t ime sl ot c ounter ove rfow t ime i s equal to the following equation shown. time slot counter overfow time= (256 - tktmr[7:0]) 32 t tsc , where t tsc is the time slot counter clock. tkc0 register bit 7 6 5 4 3 2 1 0 na ? e tkramc tkrcov tkst tkcfov tk1 ? ov tkmod tkbusy r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 bit 7 tkramc : t ouch key data ram access control 0: accessed by mcu 1: accessed by t ouch key module this bit determines that the touch key ram is used by the mcu or touch key module. however , the touch key module will have the priority to access the touch key ram when the touch key module operates in the auto scan mode, i.e., the tkst bit state is changed from 0 to 1 when the tkmod bit is set low . after the touch key auto scan operation is completed, i.e., the tkbusy bit state is changed from 1 to 0, the touch key ram access will be controlled by the tkramc bit. therefore, it is recommended to set the tkramc bit to 1 when the touch key module operates in the auto scan mode. otherwise, the contents of the touch key ram may be modifed as this ram space is confgured by the touch key module followed by the mcu access. bit 6 tkrcov : t ouch key time slot counter overfow fag 0: no overfow occurs 1: overfow occurs
rev. 1.40 ? 0 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?03 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver this bi t c an be a ccessed by a pplication progra ms. w hen t his bi t i s se t by t ouch ke y time slot counter overfow, the corrrespondingn touch key interrupt request fag will be set. however , if this bit is set by application programs, the touch key interrupt request fag will not be affected. in auto scan mode, if the time slot counter overflows but the touch key auto scan operation is not completed, the tkrcov bit will not be set. at this time, the touch key module n 16-bit c/f counter , touch key function 16-bit counter and 5-bit time slot unit period counter will be automatically cleared but the 8-bit time slot counter will be re loaded from t he 8-bi t t ime sl ot c ounter pre load re gister. w hen t he t ouch key auto scan operation is completed, the tkrcov bit and the t ouch key interrupt request flag, tkmf , will be set and all modules key and reference oscillators will automatically stop. the touch key modules 16-bit c/f counter , touch key function 16-bit counter , 5-bit time slot unit period counter and 8-bit time s lot counter w ill be automatically switched off. in manual scan mode, if the time slot counter overflows , the tkrco v bit and the touch key interrupt request fag, t kmf, will be set and all modules key and reference oscillators w ill automatically s top. the touch key module 16-bit c/f counter , touch key function 16-bit counter , 5-bit time slot unit period counter and 8-bit time slot counter will be automatically switched off. bit 5 tkst : t ouch key detection start control 0: stopped or no operation 0 1: start detection in all modules the touch key module 16-bit c/f counter , touch key function 16-bit counter and 5-bit time slot unit period counter will automatically be cle ared when this bit is clea red to zero. however , the 8-bit programmable time slot counter will not be clear ed. when this bit is changed from low to high, the touch key module 16-bit c/f counter, t ouch k ey f unction 1 6-bit c ounter, 5 -bit t ime sl ot u nie p eriod c ounter a nd 8 -bit time slot counter will be switched on together with the key and reference oscillators to drive the corresponding counters. bit 4 tkcfov : t ouch key module 16-bit c/f counter overfow fag 0: no overfow occurs 1: overfow occurs this bit is set by touch key module 16-bit c/f counter overfow and must be cleared to 0 by application programs. bit 3 tk16ov : t ouch key function 16-bit counter overfow fag 0: no overfow occurs 1: overfow occurs this bit is set by touch key function 16-bit counter overfow and must be cleared to 0 by application programs. bit 2 unimplemented, read as "0" bit 1 tkmod : t ouch key scan mode select 0: auto scan mode 1: manual scan mode in manual scan mode the reference oscillator capacitor value should be properly confgured before the scan operation begins and the touch key module 16-bit c/f counter value should be read after the scan operation fnishes by application program. in auto scan mode the data movement which is described above is implemented by hardware. the individual reference oscillator capacitor value and 16-bit c/f counter content for all scanned keys will be read from and written into a dedicated t ouch key data memory area. in auto scan mode the keys to be scaned can be arranged in a specifc sequence which is determined by the mnsk3[1:0] ~ mnsk0[1:0] bits in the tkmnc2 register. the scan operation will not be stopped until all arranged keys are scanned. bit 0 tkbusy : t ouch key scan operation busy fag 0: not busy C no scan operation is executed or scan operation is complete 1: busy C scan operation is executing this bit indicates wh ether the touch key scan operation is executing or not. it is set to 1 when the tkst bit is set high to start the scan operation and cleared to 0 when the touch key time slot counter overfows.
rev. 1.40 ?0? de?e??e? 1?? ?01? rev. 1.40 ? 03 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver tkc1 register bit 7 6 5 4 3 2 1 0 na ? e d7 d ? d ? tscs tk1 ? s1 tk1 ? s0 tkfs1 tkfs0 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 1 1 bit 7~5 d7~d5 : data bits for test only these bits are used for test purpose only and must be kept as "000" for normal operations. bit 4 tscs : t ouch key time slot counter select 0: each touch key module uses its own time slot counter 1: all touch key modules use module 0 time slot counter bit 3~2 tk16s1~tk16s0 : t ouch key function 16-bit counter clock source select 00: f sys 01: f sys /2 10: f sys /4 11: f sys /8 bit 1~0 tkfs1~tkfs0 : t ouch key oscillator and reference oscillator frequency select 00: 500 khz 01: 1000 khz 10: 1500 khz 11: 2000 khz tk16dh/tk16dl C touch key function 16-bit counter register pair register tk16dh tk16dl bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 na ? e d1 ? d14 d13 d1 ? d11 d10 d9 d8 d7 d ? d ? d4 d3 d ? d1 d0 r/w r r r r r r r r r r r r r r r r por 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 this register pair is used to store the touch key function 16-bit counter value. this 16-bit counter can be used to calibrate the reference or key oscillator frequency . when the touch key time slot counter overfows in the manual scan mode, this 16-bit counter will be stopped and the counter content will be unchanged. however, this 16-bit counter content will be cleared to zero at the end of the time slot 0, slot 1 and slot 2 but kept unchanged at the end of the time slot 3 in the auto scan mode. this register pair will be cleared to zero when the tkst bit is set low. tkmn16dh/tkmn16dl C touch key module n 16-bit c/f counter register pair register tkmn16dh tkmn16dl bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 na ? e d1 ? d14 d13 d1 ? d11 d10 d9 d8 d7 d ? d ? d4 d3 d ? d1 d0 r/w r r r r r r r r r r r r r r r r por 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 this register pair is used to store the touch key module n 16-bit c/f counter value. this 16-bit c/ f counter will be stopped and the counter content will be kept unchanged when the touch key time slot c ounter ove rfows i n t he m anual sca n m ode. howeve r, t his 16-bi t c/ f c ounter c ontent wi ll be cleared to zero at the end of the tim e slot 0, slot 1 and slot 2 but kept unchanged at the end of the time slot 3 when the auto scan mode is selected. this register pair will be cleared to zero when the tkst bit is set low.
rev. 1.40 ? 04 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?0? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver tkmnroh/tkmnrol C touch key module n reference oscillator capacitor select register pair register tkmnroh tkmnrol bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 na ? e d9 d8 d7 d ? d ? d4 d3 d ? d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 0 0 this register pair is used to store the touch key module n reference oscillator capacitor value. this register pair will be loaded with the corresponding next time slot capac itor value from the dedicated touch key data memory at the end of the current time slot when the auto scan mode is selected. the reference oscillator internal capacitor value = 1024 pf 50 x ]0:9[ tkmn . tkmnc0 register bit 7 6 5 4 3 2 1 0 na ? e mndfen d4 mnsofc mnsof ? mnsof1 mnsof0 r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 bit 7~6 unimplemented, read as "0" bit 5 mndfen : t ouch key module n multi-frequency control 0: disable 1: enable this bit is used to control the touch key oscillator frequency doubling function. when this bit is set to 1, the key oscillator frequency will be doubled. bit 4 d4 : data bit for test only the bit is used for test purpose only and must be kept as "0" for normal operations. bit 3 mnsofc : t ouch key module n c-to-f oscillator frequency hopping function control select 0: controlled by the mnsof2~mnsof0 1: controlled by hardware circuit this bit is used to select the touch key oscillator frequency hopping function control method. when this bit is set to 1, the key oscillator frequency hopping function is controlled by the hardware circuit regardless of the mnsof2~mnsof0 bits value. bit 2~0 mnsof2~mnsof0 : t ouch key module n reference and key oscillators hopping frequency select 000: f hop0 C min. hopping frequency 001: f hop1 010: f hop2 011: f hop3 100: f hop4 C selected touch key oscillator frequency 101: f hop5 110: f hop6 111: f hop7 C max. hopping frequency this bit is used to select the touch key oscillator frequency hopping function control method. when this bit is set to 1, the key oscillator frequency hopping function is controlled by the hardware circuit regardless of the mnsof2~mnsof0 bits value.
rev. 1.40 ?04 de?e??e? 1?? ?01? rev. 1.40 ? 0 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver tkmnc1 register bit 7 6 5 4 3 2 1 0 na ? e mntss mnroen mnkoen mnk4en mnk3en mnk ? en mnk1en r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 bit 7 mntss : t ouch key module n time slot counter clock source select 0: t ouch key module n reference oscillator 1: f sys /4 bit 6 unimplemented, read as "0" bit 5 mnroen : t ouch key module n reference oscillator enable control 0: disable 1: enable this bit is used to enable the touch key module n reference oscillator . in auto scan mode the referenc e oscilla tor will automatica lly be enable d by sett ing the mnroen bit high w hen the tks t bit is s et from low to high if the reference os cillator is selected a s t he t ime sl ot c lock so urce. t he c ombination o f t he mn tss, t scs a nd mnk4en~mnk1en bits determines w hether the reference os cillator is us ed or not. when the tk busy bit is changed from high to low , the m nroen bit w ill automatically be set low to disable the reference oscillator. in manua l scan mode the reference oscillator should frst be enabled before setting the tkst bit from low to high if the reference oscillator is selected to be used and will be disabled when the tkbusy bit is changed from high to low. bit 4 mnkoen : t ouch key module n key oscillator enable control 0: disable 1: enable this bit is used to enable the touch key module n key oscillator . in auto scan mode the key oscillator will automatically be enabled by setting the mnkoen bit high when the tkst bit is set form low to high. when the tkbusy bit is changed from high to low , the mnkoen bit will automatically be set low to disable the key oscillator. in manual scan mode the key oscillator shoule frst be enabled before setting the tkst bit from low to high if the relevant key is enabled to be scanned and will be disabled when the tkbusy bit is changed from high to low. bit 3 mnk4en : t ouch key module n key 4 enable control 0: disable 1: enable bit 2 mnk3en : t ouch key module n key 3 enable control 0: disable 1: enable bit 1 mnk2en : t ouch key module n key 2 enable control 0: disable 1: enable bit 0 mnk1en : t ouch key module n key 1 enable control 0: disable 1: enable
rev. 1.40 ? 0 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?07 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver tkmnc2 register bit 7 6 5 4 3 2 1 0 na ? e mnsk31 mnsk30 mnsk ? 1 mnsk ? 0 mnsk11 mnsk10 mnsk01 mnsk00 r/w r/w r/w r/w r/w r/w r/w r/w r/w por 1 1 1 0 0 1 0 0 bit 7~6 mnsk31~mnsk30 : t ouch key module n time slot 3 key scan select 00: key 1 01: key 2 10: key 3 11: key 4 these bits are used to select the desired scan key in time slot 3 and only available in the auto scan mode. bit 5~4 mnsk21~mnsk20 : t ouch key module n time slot 2 key scan select 00: key 1 01: key 2 10: key 3 11: key 4 these bits are used to select the desired scan key in time slot 2 and only available in the auto scan mode. bit 3~2 mnsk11~mnsk10 : t ouch key module n time slot 1 key scan select 00: key 1 01: key 2 10: key 3 11: key 4 these bits are used to select the desired scan key in time slot 1 and only available in the auto scan mode. bit 1~0 mnsk01~mnsk00 : t ouch key module n time slot 0 key scan select 00: key 1 01: key 2 10: key 3 11: key 4 these bits are used to select the desired scan key in time slot 0 in the auto scan mode or used as the multiplexer for scan key select in the manual mode. touch key operation when a fnger t ouches or i s i n proxi mity t o a t ouch pa d, t he c apacitance of t he pa d wi ll i ncrease. by using this capa citance variation to change slightly the frequency of the internal sense oscillator , touch act ions can be sensed by mea suring these frequency changes. using an internal programmable divider the reference clock is used to generate a fixed time period. by counting a number of generated clock cycles from the sense oscillator during this fxed time period touch key actions can be determined.
rev. 1.40 ?0? de?e??e? 1?? ?01? rev. 1.40 ? 07 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver tkst mnkoen mnroen key osc clk refe?en?e osc clk f cftmck ena?le f cftmck ( mndfen =0) f cftmck ( mndfen =0) tkbusy tkrcov ha?dwa?e set to ?0 ? set tou?h key inte??upt ?equest flag touch key mamual scan mode timing diagram each touch key module contains four touch key inputs w hich are shared logical i/o pins, and the desired function is selected using register bits. each touch key has its own independent sense oscillator. there are therefore four sense oscillators within each touch key module. during this reference clock fixed interval, the number of clock cycles generated by the s ense oscillator is measured, and it is this value that is used to determine if a touch action has been made or not. at the end of the fxed reference clock time interval a t ouch key interrupt signal will be generated in the manual scan mode. using t he t scs bi t i n t he t kc1 re gister c an se lect t he m odule 0 t ime sl ot c ounter a s t he t ime slot counter for all modules. all modules use the same started signal, tkst , in the tkc0 register . the t ouch key m odule 16-bi t c/ f counte r, 16-bi t counte r, 5-bi t t ime sl ot unit period counte r i n all m odules wi ll be a utomatically c leared whe n t he t kst b it i s c leared t o z ero, b ut t he 8- bit programmable tim e slot counter will not be cleared. the overfow time is setup by user . when the tkst bit changes from low to high, the 16-bit c/f counter, 16-bit counter, 5-bit time slot unit period counter and 8-bit time slot timer counter will be automatically switched on. the key oscillator and reference oscillator in all modules will be autom atically stopped and the 16- bit c/f counter , 16-bit counter , 5-bit time slot unit period counter and 8-bit time slot timer counter will be automatically switched of f when the time slot counter overflows. the clock source for the time slot counter is sourced from the reference oscillator or f sys /4 which is selected using the mntss bit in the tkmnc1 registe r. the reference oscillator and key oscillator will be enabled by setting the mnroen bit and mnkoen bits in the tkmnc1 register. when the time s lot counter in all the touch key modules or in the touch key module 0 overfow s, an actual touch key interrupt will take place. the touch keys mentioned here are the keys which are enabled. each touch key module consists of four touch keys, key1 ~ key4 are contained in module 0, key5 ~ ke y8 a re c ontained i n m odule 1, ke y9 ~ ke y12 a re c ontained i n m odule 3, e tc. e ach touch key module has an identical structure.
rev. 1.40 ? 08 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?09 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver auto scan mode there are two scan modes contained for the touch key function. the auto scan mode can minisize the load of the application programs and improve the touch key scan operation performance. the auto scan mode and manual scan mode are selected using the tkmod bit in the tkc0 register . when the tkmod bit is set low , the auto scan mode is selcted to scan the keys in each module in a specifc sequence determined by the mnsk3[1:0]~mnsk0[1:0] in the tkmnc2 register. tkst module 0 ti?e slot 0 ti?e slot 1 ti?e slot ? ti?e slot 3 module 1 ti?e slot 0 ti?e slot 1 ti?e slot ? ti?e slot 3 module n ti?e slot 0 ti?e slot 1 ti?e slot ? ti?e slot 3 tkbusy tkrcov clea?ed ?y softwa?e ti?e slot 1 ti?e slot ? ti?e slot 3 ti?e slot 1 ti?e slot ? ti?e slot 3 ti?e slot 1 ti?e slot ? ti?e slot 3 tou?h key data me?o?y a??ess : set tou?h key inte??upt ?equest flag : read ?n ?ytes f?o? tou?h key data me?o?y to tkmnro h/tkmnrol ?egiste?s : w?ite ?n ?ytes f?o? tkmn1?dh/tkmn1?dl ?egiste?s to tou?h key data me?o?y n = tou?h key module nu??e?; n = module se?ial nu??e? key auto s?an cy?le touch key auto scan mode timing diagram
rev. 1.40 ?08 de?e??e? 1?? ?01? rev. 1.40 ? 09 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver in the auto scan mode the key oscillator and reference oscillator will automatically be enabled when the tkst bit is set from low to high and disabled automatically when the tkbusy bit changes from high to low . when the tk st bit is s et from low to high in the auto s can mode, the f rst reference oscillator i nternal c apacitor va lue wi ll be re ad from a spe cifc l ocation of t he de dicated t ouch ke y data memory and loaded into the corresponding tkmnroh/tkmnrol registers. then the 16-bit c/f counter value will be written into the last location of the corresponding touch key module data memory. after this the selected key will be scanned in time slot 0. at the end of the time slot 0 key scan operation, the reference oscilla tor internal capacitor value for the next selected key will be read from the touch key data memory and loaded into the the next tk mnroh/tkmnrol regis ters. then the 16-bit c/f counter value of the current scanned key will be written into the corresponding touch key data memory . the whole auto scan operation will sequentially be carried out in the above specifc way from time slot 0 to time slot 3. after four keys are scanned, the tkrcov bit will be set high and the tkbusy bit will be set low . at the end of the auto scan mode, the frst reference oscillator internal capacitor value will again be read from the touch key data memory and loaded into t he correspondi ng t kmnroh/tkmnrol regi sters. t hen t he 16-bit c/ f count er val ue wi ll again be written into the relevant touch key data memory. touch key data memory the device provides two dedicated data memory area for the touch key auto scan mode. one area is us ed to s tore the 16-bit c/f counter values of the touch key module 0~n and located in d ata memory sector 5. the other area is used to store the reference oscillator internal capacitor values of the touch key module 0~n and located in data memory sector 6. device touch key data memory sector : address bs ?? f340 ? : 00h~17h ? : 00h~17h bs ?? f3 ? 0 ? : 00h~ ? 7h ? : 00h~ ? 7h bs ?? f3 ? 0 ? : 00h~37h ? : 00h~37h bs ?? f370 ? : 00h~47h ? : 00h~47h touch key data memory summary
rev. 1.40 ? 10 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ? 11 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver 10-bit ref. osc capacitor tkmnrol / tkmnroh tkm016dl_k1 tkm016dh_k1 tkm016dl_k2 tkm016dh_k2 tkm016dl_k3 tkm016dh_k3 tkm016dl_k4 tkm016dh_k4 tkm116dl_k1 tkm116dh_k1 tkm116dl_k2 tkm116dh_k2 tkm116dl_k3 tkm116dh_k3 tkm116dl_k4 tkm116dh_k4 module 0 tkm0rol_k1 tkm0roh_k1 tkm0rol_k2 tkm0roh_k2 tkm0rol_k4 tkm0roh_k4 tkm0rol_k3 tkm0roh_k3 tkm1rol_k1 tkm1roh_k1 tkm1rol_k2 tkm1roh_k2 tkm1rol_k4 tkm1roh_k4 tkm1rol_k3 tkm1roh_k3 tkm216dl_k1 tkm216dh_k1 tkm216dl_k2 tkm216dh_k2 tkm216dl_k3 tkm216dh_k3 tkm216dl_k4 tkm216dh_k4 tkm2rol_k1 tkm2roh_k1 tkm2rol_k2 tkm2roh_k2 tkm2rol_k4 tkm2roh_k4 tkm2rol_k3 tkm2roh_k3 module 1 module 2 16-bit c/f counter value (sector 5) ref. osc capacitor value (sector 6) module n tkmnrol_k1 tkmnroh_k1 tkmnrol_k2 tkmnroh_k2 tkmnrol_k4 tkmnroh_k4 tkmnrol_k3 tkmnroh_k3 tkmn16dl_k1 tkmn16dh_k1 tkmn16dl_k2 tkmn16dh_k2 tkmn16dl_k3 tkmn16dh_k3 tkmn16dl_k4 tkmn16dh_k4 00h 01h 02h xxh 16-bit c/f counter tkmn16dl / tkmn16dh touch key circuit step 1 step 2 touch key data memory map
rev. 1.40 ?10 de?e??e? 1?? ?01? rev. 1.40 ? 11 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver touch key scan operation flow chart sta?t w?ite ref. osc capa?ito? to tkmnroh/tkmnrol tou?h key manual s?an ope?ation sta?t set sta?t ?it tkst 0 1 e busy flag tkbusy=1 all ti?e slot counte? ove?flow ? tkrcov=0 initiate ti?e slot & 1?-?it c/f counte? all ti?e slot & 1?-?it c/f counte? sta?t to ?ount ti?e slot & 1?-?it c/f counte? keep ?ounting tkrcov=1 tou?h key ?usy flag tkbusy=0 gene?ate inte??upt ?equest flag read c/f ?ounte? f?o? tkmn1?dh/tkmn1?dl tou?h key s?an end set tkst ?it 1 0 end tou?h key manual s?an mode flow cha?t C tkmod=1? tscs=0
rev. 1.40 ? 1 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?13 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver sta?t w?ite ref. osc inte?nal capa?ito? value to data me?o?y (se?to? ? ) touch key auto scan operation start set sta?t ?it tkst 0 1 e busy flag tkbusy=1 all ti?e slot counte? ove?flow ? no initiate ti?e slot & 1?-?it c/f counte? all ti?e slot ?ounte? & 1?-?it c/f ?ounte? sta?t to ?ount ti?e slot & 1?-?it c/f counte? keep ?ounting yes tkrcov = 1 gene?ate inte??upt ?equest flag read c/f ?ounte? value f?o? data me?o?y (se?to? ?) tou?h key s?an end set tkst ?it 1 0 end load ref. osc inte?nal capa?ito? value f?o? data me?o?y (se?to? ? ) sto?e c/f ?ounte? value to data me?o?y (se?to? ? ) all key s?an finish ? yes no tou?h key ?usy flag tkbusy=0 change next key touch key auto scan mode flow chart C tkmod=0, tscs=0 touch key interrupt the touch key only has single inter rupt, when the time slot counter in all the touch key modules or in the touch key module 0 overfows, an actual touch key interrupt will take place. the touch keys mentioned he re a re t he ke ys whi ch a re e nabled. t he 16-bi t c/ f c ounter, 16-bi t c ounter, 5-bi t t ime slot unit period counter and 8-bit time slot counter in all modules will be automatically cleared. progrsmming considerations after t he rel evant regi sters are se tup, t he t ouch key det ection process i s i nitiated t he cha nging t he tkst bit from low to high. this will enable and synchronise all releva nt oscillators. the tkrcov fag which is the time slot counter fag will go high when the counter overfows. when this happens an interrupt signal will be generated. when the external touch key size and layout are defined, their related capacitances will then determine the sensor oscillator frequency.
rev. 1.40 ?1? de?e??e? 1?? ?01? rev. 1.40 ? 13 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver low voltage detector C lvd each device has a low v oltage detector function, also known as l vd. this enabled the device to monitor the power supply voltage, v dd , and provide a warning signal should it fall below a certain level. this function may be especially useful in battery applications where the supply voltage will gradually reduce as the battery ages, as it allows an early warning battery low signal to be generated. the low v oltage detector also has the capability of generating an interrupt signal. lvd register the low voltage detector function is controlled using a single register with the name l vdc. three bits in this register , vl vd2~vlvd0, are used to select one of eight fxed voltages below which a l ow vo ltage c ondition wi ll be de termined. a l ow vo ltage c ondition i s i ndicated whe n t he l vdo bit is set. if the l vdo bit is low , this indicates that the v dd voltage is above the preset low voltage value. the l vden bit is used to control the overall on/of f function of the low voltage detector . setting the bit high will enable the low voltage detector . clearing the bit to zero will switch of f the internal low voltage detector circuits. as the low voltage detector will consume a certain amount of power, it may be desirable to switch of f the circuit when not in use, an important consideration in power sensitive battery powered applications. lvdc register bit 7 6 5 4 3 2 1 0 na ? e lvdo lvden vbgen vlvd ? vlvd1 vlvd0 r/w r r/w r/w r/w r/w r/w por 0 0 0 0 0 0 bit 7~6 uunimplemented, read as "0" bit 5 lvdo : lvd output fag 0: no low v oltage detected 1: low v oltage detected bit 4 lvden : low v oltage detector enable control 0: disable 1: enable bit 3 vbgen : bandgap v oltage output enable control 0: disable 1: enable bit 2~0 vlvd2~vlvd0 : lvd v oltage selection 000: 2.0v 001: 2.2v 010: 2.4v 011: 2.7v 100: 3.0v 101: 3.3v 110: 3.6v 111: 4.0v
rev. 1.40 ? 14 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?1? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver lvd operation the low v oltage detector function operates by comparing the power supply voltage, v dd , with a pre-specifed volta ge level stored in the l vdc register . this has a range of between 2.0v and 4.0v . when the power supply voltage, v dd , falls below this pre-determined value, the l vdo bit will be set high indicating a low power supply voltage condition. the low v oltage detector function is supplied by a reference voltage which will be automatically enabled. when the device is powered down the low voltage detector will remain active if the l vden bit is high. after enabling the low voltage detector , a time delay t lvds should be allowed for the circuitry to stabilise before reading the lvdo bit. note also that as the v dd voltage may rise and fall rather slowly , at the voltage nears that of v lvd , there may be multiple bit lvdo transitions.              lvd operation the low v oltage detector also has its own interrupt which is contained within one of the multi- function interrupts, providing an alternative means of low voltage detection, in addition to polling the l vdo bit. the interrupt will only be generated after a delay of t lvd after the l vdo bit has been set high by a low voltage condition. when the device is powered down the low v oltage detector will rema in active if the l vden bit is high. in this case, the l vf interrupt request fag will be set, causing an interru pt to be generated if v dd falls below the preset l vd voltage. this will cause the device to wake-up from the sleep or idle mode, however if the low v oltage detector wake up function is not required then the lvf fag should be frst set high before the device enters the sleep or idle mode.
rev. 1.40 ?14 de?e??e? 1?? ?01? rev. 1.40 ? 1 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver interrupts interrupts are an important part of any microcontroller s ystem. when an external event or an internal function such as a t imer module or an a/d converter requires microcontroller attention, their corresponding interrupt will enforce a temporary suspension of the main program allowing the microcontroller to direct attention to their respective needs. these devices contain several external interrupt and internal interrupts functions . the external interrupts are generated by the action of the external int0 and int1 pins, while the internal interrupts are generated by various internal functions such as the tms, t ouch key , t ime base, l vd, eeprom, sim, uar t and the a/d converter, etc. interrupt registers overall interrupt control, w hich bas ically means the s etting of reques t flags w hen certain microcontroller conditions occur and the setting of interrupt enable bits by the application program, is control led by a series of registers, located in the special purpose data memory , as shown in the accompanying table. the number of registers depends upon the device chosen but fall into three categories. t he frst i s t he int c0~intc2 re gisters whi ch se tup t he pri mary i nterrupts, t he se cond is the mfi0~mfi3 registers which setup the multi-function interrupts. finally there is an integ register to setup the external interrupt trigger edge type. each register contains a number of enable bits to enable or disable individual interrupts as well as i nterrupt fa gs t o i ndicate t he p resence o f a n i nterrupt r equest. t he n aming c onvention o f t hese follows a specifc pattern. first is listed an abbreviated interrupt type, then the (optional) number of that interrupt followed by either an "e" for enable/disable bit or "f" for request fag. function enable bit request flag notes glo ? al emi intn pins intne intnf n = 0 ~ 1 tou ? h key tkme tkmf uart ure urf multi-fun ? tion mfne mfnf n = 0 ~ 3 a/d conve ? te ? ade adf ti ? e base tbne tbnf n = 0 ~ 1 lvd lve lvf eeprom w ? ite ope ? ation dee def sim sime simf ctm ctmnpe ctmnpf n = 0 ~ 1 ctmnae ctmnaf ptm ptmpe ptmpf ptmae ptmaf stm stmpe stmpf stmae stmaf interrupt register bit naming conventions
rev. 1.40 ? 1 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?17 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver register name bit 7 6 5 4 3 2 1 0 integ int1s1 int1s0 int0s1 int0s0 intc0 tkmf int1f int0f tkme int1e int0e emi intc1 adf mf1f mf0f urf ade mf1e mf0e ure intc ? mf3f tb1f tb0f mf ? f mf3e tb1e tb0e mf ? e mfi0 ctm0af ctm0pf ctm0ae ctm0pe mfi1 stmaf stmpf ctm1af ctm1pf stmae stmpe ctm1ae ctm1pe mfi ? simf ptmaf ptmpf sime ptmae ptmpe mfi3 def lvf dee lve interrupt registers list integ register bit 7 6 5 4 3 2 1 0 na ? e int1s1 int1s0 int0s1 int0s0 r/w r/w r/w r/w r/w por 0 0 0 0 bit 7~4 unimplemented, read as "0" bit 3~2 int1s1~int1s0 : interrupt edge control for int1 pin 00: disable 01: rising edge 10: falling edge 11: rising and falling edges bit 1~0 int0s1~int0s0 : interrupt edge control for int0 pin 00: disable 01: rising edge 10: falling edge 11: rising and falling edges intc0 register bit 7 6 5 4 3 2 1 0 na ? e tkmf int1f int0f tkme int1e int0e emi r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 bit 7 unimplemented, read as "0" bit 6 tkmf : t ouch key interrupt request fag 0: no request 1: interrupt request bit 5 int1f : int1 interrupt request fag 0: no request 1: interrupt request bit 4 int0f : int0 interrupt request fag 0: no request 1: interrupt request bit 3 tkme : t ouch key interrupt control 0: disable 1: enable bit 2 int1e : int1 interrupt control 0: disable 1: enable bit 1 int0e : int0 interrupt control 0: disable 1: enable
rev. 1.40 ?1? de?e??e? 1?? ?01? rev. 1.40 ? 17 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 0 emi : global interrupt control 0: disable 1: enable intc1 register bit 7 6 5 4 3 2 1 0 na ? e adf mf1f mf0f urf ade mf1e mf0e ure r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7 adf : a/d converter interrupt request fag 0: no request 1: interrupt request bit 6 mf1f : multi-function 1 interrupt request fag 0: no request 1: interrupt request bit 5 mf0f : multi-function 0 interrupt request fag 0: no request 1: interrupt request bit 4 urf : uart transfer interrupt request fag 0: no request 1: interrupt request bit 3 ade : a/d converter interrupt control 0: disable 1: enable bit 2 mf1e : multi-function 1 interrupt control 0: disable 1: enable bit 1 mf0e : multi-function 0 interrupt control 0: disable 1: enable bit 0 ure : uart transfer interrupt control 0: disable 1: enable intc2 register bit 7 6 5 4 3 2 1 0 na ? e mf3f tb1f tb0f mf ? f mf3e tb1e tb0e mf ? e r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7 mf3f : multi-function 3 interrupt request fag 0: no request 1: interrupt request bit 6 tb1f : t ime base 1 interrupt request fag 0: no request 1: interrupt request bit 5 tb0f : t ime base 0 interrupt request fag 0: no request 1: interrupt request bit 4 mf2f : multi-function 2 interrupt request fag 0: no request 1: interrupt request bit 3 mf3e : multi-function 3 interrupt control 0: disable 1: enable
rev. 1.40 ? 18 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?19 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 2 tb1e : t ime base 1 interrupt control 0: disable 1: enable bit 1 tb0e : t ime base 0 interrupt control 0: disable 1: enable bit 0 mf2e : multi-function 2 interrupt control 0: disable 1: enable mfi0 register bit 7 6 5 4 3 2 1 0 na ? e ctm0af ctm0pf ctm0ae ctm0pe r/w r/w r/w r/w r/w por 0 0 0 0 bit 7~6 unimplemented, read as "0" bit 5 ctm0af : ctm0 comparator a match interrupt request fag 0: no request 1: interrupt request bit 4 ctm0pf : ctm0 comparator p match interrupt request fag 0: no request 1: interrupt request bit 3~2 unimplemented, read as "0" bit 1 ctm0ae : ctm0 comparator a match interrupt control 0: disable 1: enable bit 0 ctm0pe : ctm0 comparator p match interrupt control 0: disable 1: enable mfi1 register bit 7 6 5 4 3 2 1 0 na ? e stmaf stmpf ctm1af ctm1pf stmae stmpe ctm1ae ctm1pe r/w r/w r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 0 0 bit 7 stmaf : stm comparator a match interrupt request fag 0: no request 1: interrupt request bit 6 stmpf : stm comparator p match interrupt request fag 0: no request 1: interrupt request bit 5 ctm1af : ctm1 comparator a match interrupt request fag 0: no request 1: interrupt request bit 4 ctm1pf : ctm1 comparator p match interrupt request fag 0: no request 1: interrupt request bit 3 stmae : stm comparator a match interrupt control 0: disable 1: enable bit 2 stmpe : stm comparator p match interrupt control 0: disable 1: enable
rev. 1.40 ?18 de?e??e? 1?? ?01? rev. 1.40 ? 19 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bit 1 ctm1ae : ctm1 comparator a match interrupt control 0: disable 1: enable bit 0 ctm1pe : ctm1 comparator p match interrupt control 0: disable 1: enable mfi2 register bit 7 6 5 4 3 2 1 0 na ? e simf ptmaf ptmpf sime ptmae ptmpe r/w r/w r/w r/w r/w r/w r/w por 0 0 0 0 0 0 bit 7 unimplemented, read as "0" bit 6 simf : sim interrupt request fag 0: no request 1: interrupt request bit 5 ptmaf : ptm comparator a match interrupt request fag 0: no request 1: interrupt request bit 4 ptmpf : ptm comparator p match interrupt request fag 0: no request 1: interrupt request bit 3 unimplemented, read as "0" bit 2 sime : sim interrupt control 0: disable 1: enable bit 1 ptmae : ptm comparator a match interrupt control 0: disable 1: enable bit 0 ptmpe : ptm comparator p match interrupt control 0: disable 1: enable mfi3 register bit 7 6 5 4 3 2 1 0 na ? e def lvf dee lve r/w r/w r/w r/w r/w por 0 0 0 0 bit 7~6 unimplemented, read as "0" bit 7 def : data eeprom interrupt request fag 0: no request 1: interrupt request bit 4 lvf : lvd interrupt request fag 0: no request 1: interrupt request bit 3~2 unimplemented, read as "0" bit 1 dee : data eeprom interrupt control 0: disable 1: enable bit 0 lve : lvd interrupt control 0: disable 1: enable
rev. 1.40 ?? 0 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ??1 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver interrupt operation when the conditions for an interrupt event occur, such as a tm comparator p or comparator a or a/ d conversion completion, etc, the relevant interrupt request fag will be set. whether the request fag actually generates a program jump to the relevant interrupt vector is determined by the condition of the interrupt enabl e bit. if the enable bit is set high then the program will jump to its relevant vector; if the enable bit is zero then although the interrupt request fag is set an actual interrupt will not be generated and the program will not jump to the relevant interrupt vector . the global interrupt enable bit, if cleared to zero, will disable all interrupts. when an interrupt is generated, the program counter, which stores the address of the next instruction to be executed, will be transferred onto the stack. the program counter will then be loaded with a new address which will be the value of the corresponding interrupt vector . the microcontroller will then fetch its next instruction from this interrupt vector . the instruction at this vector will usually be a jmp which will jump to another section of program which is known as the interrupt service routine. here is located the code to control the appropriate interrupt. the interrupt service routine must be terminated with a reti, which retrieves the original program counter address from the stack and allow s the microcontroller to continue w ith normal execution at the point w here the interrupt occurred. the various interrupt enable bits, together with their associated request flags, are shown in the accompanying diagrams with their order of priority . some interrupt sources have their own individual vector w hile others s hare the s ame multi-function interrupt vector . o nce an interrupt subroutine is serviced, all other interrupts will be blocked, as the global interrupt enable bit, emi bit will be cleared automatically . this will prevent any further interrupt nesting from occurring. however, i f ot her i nterrupt re quests oc cur duri ng t his i nterval, a lthough t he i nterrupt wi ll not be immediately serviced, the request fag will still be recorded. if an interrupt requires immediate servicing while the program is alread y in another interrupt service routine, the emi bit should be set after entering the routine to allow interrupt nesting. if the stack is full, the interrupt request will not be acknowledged, even if the related interrupt is enabled, until the stack pointer is decremented. if immediate service is desired, the stack must be prevented from becoming full. in case of simultaneous requests, the accompanying diagram shows the priority that is a pplied. al l o f t he i nterrupt r equest fa gs wh en se t wi ll wa ke-up t he d evice i f i t i s i n sl eep o r idle mode, however to prevent a wake-up from occurring the corresponding fag should be set before the device is in sleep or idle mode.
rev. 1.40 ??0 de?e??e? 1?? ?01? rev. 1.40 ?? 1 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver int0 pin int1 pin int0f int1f int0e int1e emi 04h emi 08h m. fun?t. 0 mf0f mf0e emi 0ch emi 10h emi 14h ti?e base 0 tb0f tb0e emi 18h lvd lvf lve emi 1ch inte??upt na?e request flags ena?le bits maste? ena?le vector emi auto disa?led in isr p?io?ity high low m. fun?t. 1 mf1f mf1e ctm0 p ctm0pf ctm0pe ctm0 a ctm0af ctm0ae inte??upts ?ontained within multi-fun?tion inte??upts xxe ena?le bits xxf request flag? auto ?eset in isr legend xxf request flag? no auto ?eset in isr emi ?0h a/d adf ade emi ?4h m. fun?t. ? mf?f mf?e ti?e base 1 tb1f tb1e m. fun?t. 3 mf3f mf3e eeprom def dee sim simf sime uart urf ure emi ?8h ctm1 p ctm1pf ctm1pe ctm1 a ctm1af ctm1ae emi ?ch tou?h key tkmf tkme stm p stmpf stmpe stm a stmaf stmae ptm p ptmpf ptmpe ptm a ptmaf ptmae interrupt scheme external interrupt the external interrupts are controlled by signal transitions on the pins int0~int1. an external interrupt request will take place when the external interrupt request fags, int0f~int1f , are set, which will occur when a transition, whose type is chosen by the edge select bits, appears on the external interrupt pins . t o allow the program to branch to its res pective interrupt vector addres s, the g lobal i nterrupt e nable b it, e mi, a nd r espective e xternal i nterrupt e nable b it, i nt0e~int1e, must first be set. additionally the correct interrupt edge type mus t be selected using the integ register to enable the external interrupt function and to choose the trigger edge type. as the external interrupt pins are pin-shared with i/o pins, they can only be confgured as external interrupt pins if their external interrupt enable bit in the corresponding interrupt register has been set and the external interrupt pin is selected by the corresponding pin-shared function selection bits. the pin must also be setup as an input by setting the corresponding bit in the port control register . when the interrupt is enabled, the stack is not full and the correct transition type appears on the external interrupt pin, a subroutine call to the external interrupt vector , will take place. when the interrupt is serviced, the external interrupt request fags, int0f~int1f , will be automatically reset and the emi bit will be automatically cleared to disable other interrupts. note that any pull-high resistor selections on the external interrupt pins will remain valid even if the pin is used as an external interrupt input. the integ register is used to select the type of active edge that will trigger the external interrupt. a choice of either rising or falling or both edge types can be chosen to trigger an external interrupt. note that the integ register can also be used to disable the external interrupt function.
rev. 1.40 ??? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ??3 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver touch key interrupt for a t ouch key interrupt to occur, the global interrupt enable bit, emi, and the t ouch key interrupt enable tkme must be frst set. an actual t ouch key interrupt will take place when the t ouch key request fag, tkmf , is set, a situation that will occur when the time slot counter overfows. when the interrupt is enabled, the stack is not full and the t ouch key time slot counter overfow occurs, a subroutine call to the relevant timer interrupt vector , will take place. when the interrupt is serviced, the t ouch key interrupt request fag, tkmf , will be automatically reset and the emi bit will be automatically cleared to disable other interrupts. uart transfer interrupt the uar t t ransfer interrupt is controlled by several uar t transfer conditions. when one of these conditions occurs, an interrupt pulse will be generated to get the attention of the microcontroller . these conditions are a transmitter data register empty , transmitter idle, receiver data available, receiver overrun, address detect and an rx pin wake-up. t o allow the program to branch to its respective interrupt vector address, the global interrupt enable bit, emi, and uar t interrupt enable bit, ure, must frst be set. when the interrupt is enabled, the stack is not full and any of the conditions described above occurs, a subroutine call to the uar t interrupt vector , will take place. when the interrupt is serviced, the uar t interrupt fag, urf , will be automatically cleared. the emi bit will also be automatically cleared to disable other interrupts. a/d converter interrupt the a/d converter interrupt is controlled by the termination of an a/d conversion process. an a/ d converter interrupt request will take place when the a/d converter interrupt request fag, adf , is set, which occurs when the a/d conversion process fnishes. t o allow the program to branch to its respective interrupt vector address, the global interrupt enable bit, emi, a nd a/ d interrupt enable bit, ade, must frst be set. when the interrupt is enabled, the stack is not full and the a/d conversion process has ended, a subroutine call to the a/d converter interrupt vector , will take place. when the interrupt is serviced, the a/d converter interrupt fag, adf , will be automatically cleared. the emi bit will also be automatically cleared to disable other interrupts. multi-function interrupt within the device there are up to four multi-function interrupts. unlike the other independent interrupts, these interrupts have no independent source, but rather are formed from other existing interrupt sources, namely the tm interrupts, l vd interrupt, eeprom write operation interrupt and sim interface interrupts. a multi-function interrupt request will take place when any of the multi-function interrupt request flags mfnf are set. the multi-function interrupt flags will be set when any of their included functions generate an interrupt request fag. t o allow the program to branch to its respective interrupt vector address, when the multi-func tion interrupt is enabled and the stack is not full, and either one of the interrupts contained within each of multi-function interrupt occurs, a subroutine call to one of the multi-function interrupt vectors will take place. when the interrupt is serviced, the related multi- function request fag will be automatically reset and the emi bit will be automatically cleared to disable other interrupts. however, it must be noted that, although the multi-function interrupt request flags will be automatically reset when the interrupt is serviced, the request flags from the original source of the multi-function interrupts will not be automatically reset and must be manually reset by the application program.
rev. 1.40 ??? de?e??e? 1?? ?01? rev. 1.40 ?? 3 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver time base interrupt the function of the t ime base interrupt is to provide regular time signal in the form of an internal interrupt. it is controlled by the overflow signal from its internal timer . when this happens its interrupt request fag, tbnf , will be set. t o allow the program to branch to its respective interrupt vector addresses, the global interrup t enable bit, emi and t ime base enable bit, tbne, must frst be set. when the interrupt is enabl ed, the stack is not full and the t ime base overfows, a subroutine call to its respective vector location will take place. when the interrupt is serviced, the interrupt request flag, tbnf , will be automatically reset and the emi bit will be cleared to disable other interrupts. the purpose of the t ime base interrupt is to provide an interrupt signal at fxed time periods. its clock source, f psc0 or f psc1 , originates from the internal clock source f sys , f sys /4 or f sub and then passes through a divider , the division ratio of which is selected by programming the appropriate bits in the tb0c and tb1c registers to obtain longer interrupt periods whose value ranges. the clock source whi ch i n t urn c ontrols t he t ime ba se i nterrupt pe riod i s se lected usi ng t he cl ksel0[1:0] and clksel1[1:0] bits in the pscr0 and pscr1 register respectively. m u x f sys /4 f sys f sub p?es?ale? 0 clksel0[1:0] f psc0 f psc0 /? 8 ~ f psc0 /? 1? m u x m u x tb0[?:0] tb1[?:0] ti?e base 0 inte??upt ti?e base 1 inte??upt tb0on tb1on m u x f sys /4 f sys f sub p?es?ale? 1 clksel1[1:0] f psc1 f psc1 /? 8 ~ f psc1 /? 1? time base interrupts pscr0 register bit 7 6 5 4 3 2 1 0 na ? e clksel01 clksel00 r/w r/w r/w por 0 0 bit 7~2 unimplemented, read as "0" bit 1~0 clksel01~clksel00 : prescaler 0 clock source selection 00: f sys 01: f sys /4 1x: f sub pscr1 register bit 7 6 5 4 3 2 1 0 na ? e clksel11 clksel10 r/w r/w r/w por 0 0 bit 7~2 unimplemented, read as "0" bit 1~0 clksel11~clksel10 : prescaler 1 clock source selection 00: f sys 01: f sys /4 1x: f sub
rev. 1.40 ?? 4 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ??? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver tb0c register bit 7 6 5 4 3 2 1 0 na ? e tb0on tb0 ? tb01 tb00 r/w r/w r/w r/w r/w por 0 0 0 0 bit 7 tb0on : t ime base 0 enable control 0: disable 1: enable bit 6~3 unimplemented, read as "0" bit 2~0 tb02~tb00 : t ime base 0 time-out period selection 000: 2 8 /f psc0 001: 2 9 /f psc0 010: 2 10 /f psc0 011: 2 11 /f psc0 100: 2 12 /f psc0 101: 2 13 /f psc0 110: 2 14 /f psc0 111: 2 15 /f psc0 tb1c register bit 7 6 5 4 3 2 1 0 na ? e tb1on tb1 ? tb11 tb10 r/w r/w r/w r/w r/w por 0 0 0 0 bit 7 tb1on : t ime base 1 enable control 0: disable 1: enable bit 6~3 unimplemented, read as "0" bit 2~0 tb12~tb10 : t ime base 1 time-out period selection 000: 2 8 /f psc1 001: 2 9 /f psc1 010: 2 10 /f psc1 011: 2 11 /f psc1 100: 2 12 /f psc1 101: 2 13 /f psc1 110: 2 14 /f psc1 111: 2 15 /f psc1 serial interface module interrupt the serial interface module interrupt, also known as the sim interrupt, is contained within the multi-function interrupt. a sim interrupt request will take place when the sim interrupt request fag, simf , is set, which occurs when a byte of data has been received or transmitted by the sim interface, an i 2 c slave address match or i 2 c bus time-out occurrence. t o allow the program to branch t o i ts r espective i nterrupt v ector a ddress, t he g lobal i nterrupt e nable b it, e mi, t he se rial interface interrupt enable bit, sime, and muti-function interrupt enable bit must frst be set. when the i nterrupt i s e nabled, t he st ack i s n ot f ull a nd a ny o f t he a bove d escribed si tuations o ccurs, a subroutine c all t o t he re spective mul ti-function in terrupt ve ctor, wi ll t ake pl ace. w hen t he se rial interface interrupt is serviced, the emi bit will be automatically cleare d to disable other interrupts, however only the multi-function interrupt request fag will be also automatically cleared. as the simf fag will not be automatically cleared, it has to be cleared by the application program.
rev. 1.40 ??4 de?e??e? 1?? ?01? rev. 1.40 ??? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver lvd interrupt the l ow v oltage de tector i nterrupt i s c ontained wi thin t he mu lti-function i nterrupt. an l vd interrupt reques t w ill take place w hen the l vd interrupt request flag, l vf, is s et, w hich occurs when the low v oltage detector function detects a low power supply voltage. t o allow the program to branch to its respective interrupt vector address, the global interrupt enable bit, emi, low v oltage interrupt enable bit, l ve, and associated multi-function interrupt enable bit, must frst be set. when the interrupt is enabled, the stack is not full and a low voltage conditio n occurs, a subroutine call to the multi-function interrupt vector , will take place. when the low v oltage interrupt is serviced, the emi bit will be automatically clear ed to disable other interrupts. however , only the multi-function interrupt request fag will be also automatically cleared. as the l vf fag will not be automatically cleared, it has to be cleared by the application program. eeprom interrupt the eeprom w rite interrupt is contained within the multi-function interrupt. an eeprom write interrupt request will take place when the eeprom w rite interrupt request fag, def , is set, which occurs when an eeprom w rite cycle ends. t o allow the program to branch to its respective interrupt vector address, the global interrupt enable bit, emi, eeprom w rite interrupt enable bit, dee, and associated multi-function interrupt enable bit must first be set. when the interrupt is enabled, the stack is not full and an eeprom w rite cycle ends, a subroutine call to the respective multi-function interrupt vector will take place. when the eeprom w rite interrupt is serviced, the emi bit will be automatically clear ed to disable other interrupts. however , only the multi-function interrupt request flag will be automatically cleared. as the def flag will not be automatically cleared, it has to be cleared by the application program. tm interrupt the compact, standard and periodic tms have two interrupts, one comes from the comparator a match situation and the other comes from the comparator p match situation. all of the tm interrupts are contained within the multi-function interrupts. for all of the tm types there are two interrupt request fa gs and two enable control bit s. a tm int errupt reque st wi ll ta ke plac e when any of the tm re quest fa gs a re se t, a si tuation whi ch oc curs whe n a t m c omparator p or a m atch si tuation happens. to allow the program to branch to its respective interrupt vector address, the global interrupt enable bit, emi, respective tm interrupt enable bit, and relevant multi-function interrupt enable bit, mfne, must frst be set. when the interrupt is enabled, the stack is not full and a tm comparator match situation occurs, a subroutine call to the relevant multi-function interrupt vector locations, will take place. when the tm interrupt is serviced, the emi bit will be automatically cleared to disable other interrupts. however , only the related mfnf fag will be automatically cleared. as the tm interrupt request fags will not be automatically cleared, they have to be cleared by the application program.
rev. 1.40 ??? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ??7 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver interrupt wake-up function each of the int errupt funct ions has the ca pability of waki ng up the mi crocontroller when in the sleep o r i dle mo de. a wa ke-up i s g enerated wh en a n i nterrupt r equest fa g c hanges f rom l ow to high and is independent of whether the interrupt is enabled or not. therefore, even though these devices are in the sleep or idle mode and its system oscillator stopped, situations such as external edge transitions on the external interrupt pins, a low power supply voltage or comparator input change may cause their re spective interrupt fl ag to be set hi gh and consequently ge nerate an i nterrupt. c are m ust t herefore b e t aken i f sp urious wa ke-up si tuations a re t o b e a voided. i f a n interrupt wake-up function is to be disabled then the corresponding interrupt request fag should be set high before the device enters the sleep or idle mode. the interr upt enable bits have no ef fect on the interrupt wake-up function. programming considerations by di sabling t he re levant i nterrupt e nable bi ts, a re quested i nterrupt c an be pre vented from be ing serviced, however , once an interrupt request flag is set, it will remain in this condition in the interrupt register until the corresponding interrupt is serviced or until the request fag is cleared by the application program. where a certain interrupt is contained w ithin a m ulti-function interrupt, then w hen the interrupt service routine is executed, as only the multi-function interrupt request flags, mfnf , will be automatically cleared, the individual request flag for the function needs to be cleared by the application program. it is recommended that programs do not use the "call" instruction within the interrupt service subroutine. interrupts often occur in an unpredictable manner or need to be serviced immediately . if only one stack is left and the inte rrupt is not well controlled, the original control sequence will be damaged once a call subroutine is executed in the interrupt subroutine. every interrupt has the capability of waking up the microcontroller when it is in the sleep or idle mode, the wake up being generated when the interrupt request fag changes from low to high. if it is required to prevent a certain interru pt from waking up the microcontrol ler then its respective request fag should be frst set high before enter sleep or idle mode. as only the program counter is pushed onto the stack, then when the interrupt is serviced, if the contents of the accumulator , status register or other registers are altered by the interrupt service program, t heir c ontents shoul d be sa ved t o t he m emory a t t he be ginning of t he i nterrupt se rvice routine. to return from an interrupt subroutine, either a ret or reti instruction may be executed. the reti instruction in addition to executing a return to the main program also automatically sets the emi bit high to allow further interrupts. the ret instruction however only executes a return to the main program leaving the emi bit in its present zero state and therefore disabling the execution of further interrupts.
rev. 1.40 ??? de?e??e? 1?? ?01? rev. 1.40 ?? 7 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver application circuits a/d rx vdd vss bs66f3x0 10uf 0.1uf v dd rs488 t?ans?eive? tx i/o rs_dir analog signals i/o key1 keyx xt1 xt? 3?7?8hz tm pwm / captu?e tm buzze? spi/i ? c co??uni?ation devi?e osc1 osc? syste? c?ystal i/o cont?ol devi?e
rev. 1.40 ?? 8 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ??9 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver instruction set introduction central to the successful operation of any microcontroller is its instruction set, which is a set of program instruction codes that direc ts the microcontroller to perform certain operations. in the case of holtek microcontroller , a comprehensive and fexible set of over 60 instructions is provided to enable programmers to implement their application with the minimum of programming overheads. for easier understanding of the various instruction codes, they have been subdivided into several functional groupings. instruction timing most instructions are implemented within one instruction cycle. the exceptions to this are branch, call, or table read instructions where two ins truction cycles are required. one instruction cycle is equal to 4 system clock cycles, therefore in the case of an 8mhz system oscillator , most instructions would be i mplemented wi thin 0.5 s a nd bra nch or c all i nstructions woul d be i mplemented wi thin 1s. although instructions which require one more cycle to implement are generally limited to the jmp , call, ret , reti and table read instructions, it is important to realize that any other instructions which involve manipulation of the program counter low register or pcl will also take one more cycle to implement. as instructions which change the contents of the pcl will imply a direct j ump t o t hat ne w a ddress, one m ore c ycle wi ll be re quired. e xamples of suc h i nstructions would be "clr pcl" or "mov pcl, a". for the case of skip instructions, it must be noted that if the result of the comparison involves a skip operation then this will also take one more cycle, if no skip is involved then only one cycle is required. moving and transferring data the t ransfer of da ta wi thin t he m icrocontroller progra m i s one of t he m ost fre quently use d operations. making use of three kinds of mov instructions, data can be transferred from registers to the accumulator and vice-versa as well as being able to move specifc immediate data directly into the ac cumulator. one of t he m ost i mportant da ta t ransfer a pplications i s t o re ceive da ta from t he input ports and transfer data to the output ports. arithmetic operations the ability to perform certain arithm etic operations and data manipula tion is a necessary feature of most m icrocontroller a pplications. w ithin t he hol tek m icrocontroller i nstruction se t a re a ra nge of add and subtract instruction mnemonics to enable the necessary arithmetic to be carried out. care must be taken to ens ure correct handling of carry and borrow data w hen res ults exceed 255 for addition and less than 0 for subtraction. the increment and decrement instructions inc, inca, dec and deca provide a simple means of increasing or decreasing by a value of one of the values in the destination specifed.
rev. 1.40 ??8 de?e??e? 1?? ?01? rev. 1.40 ?? 9 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver logical and rotate operation the standard logical operations such as and, or, xor and cpl all have their own instruction within t he hol tek m icrocontroller i nstruction se t. as wi th t he c ase of m ost i nstructions i nvolving data m anipulation, d ata m ust p ass t hrough t he ac cumulator wh ich m ay i nvolve a dditional programming steps. in all logical data operations, the zero flag may be set if the result of the operation is zero. another form of logical data manipulation comes from the rotate instructions such as rr, rl, rrc and rlc which provide a simple means of rotating one bit right or left. dif ferent rotate instructions exist depending on program requirements. rotate instructions are useful for serial port progra mming a pplications whe re da ta c an be rot ated from a n i nternal re gister i nto t he ca rry bit from where it can be examined and the necessary serial bit set high or low . another application which rotate data operations are used is to implement multiplication and division calculations. branches and control transfer program branching takes the form of either jumps to specifed locations using the jmp instruction or t o a su broutine usi ng t he cal l i nstruction. t hey di ffer i n t he se nse t hat i n t he c ase of a subroutine call, the program mus t return to the ins truction immediately w hen the s ubroutine has been carried out. this is done by placing a return ins truction " ret" in the s ubroutine w hich w ill cause the program to jump back to the address right after the call instruction. in the case of a jmp instruction, the program simply jumps to the desired location. there is no requirement to jump back to the original jumping of f point as in the case of the call instruction. one special and extremely useful set of branch instructions are the conditional branches. here a decision is frst made regarding the condition of a certain data memory or individual bits. depending upon the conditions, the program will continue with the next instruction or skip over it and jump to the following instruction. these i nstructions a re t he ke y t o de cision m aking a nd bra nching wi thin t he progra m pe rhaps determined by the condition of certain input switches or by the condition of internal data bits. bit operations the abili ty to provide single bit operations on data memory is an extremely fexible feature of all holtek m icrocontrollers. t his fe ature i s e specially use ful for out put port bi t progra mming whe re individual bits or port pins can be directly set high or low using either the "set [m].i" or "clr [m]. i" i nstructions r espectively. t he f eature r emoves t he n eed f or p rogrammers t o fr st r ead t he 8 -bit output port, manip ulate the input data to ensure that other bits are not changed and then output the port with the correct new data. this read-modify-write process is take n care of automatically when these bit operation instructions are used. table read operations data st orage i s norm ally i mplemented by usi ng re gisters. however , whe n worki ng wi th l arge amounts of fxed data, the volume involved often makes it inconvenient to store the fxed data in the data memory . t o overcome this problem, holtek microcontrollers allow an area of program memory to be set as a table where data can be directly stored. a set of easy to use instructions provides the means by w hich this fixed data can be referenced and retrieved from the program memory. other operations in addition to the above functional instructions, a range of other instructions also exist such as the "hal t" i nstruction f or po wer-down o perations a nd i nstructions t o c ontrol t he o peration o f the w atchdog t imer for reliable program operations under extreme electric or electromagnetic environments. for their relevant operations, refer to the functional related sections.
rev. 1.40 ? 30 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?31 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver instruction set summary the i nstructions re lated t o t he da ta m emory a ccess i n t he fol lowing t able c an be use d whe n t he desired data memory is located in data memory sector 0. table conventions x: bits immediate data m: data memory address a: accumulator i: 0~7 number of bits addr: program memory address mnemonic description cycles flag affected arithmetic add a ? [ ? ] add data me ? o ? y to acc 1 z ? c ? ac ? ov ? sc addm a ? [ ? ] add acc to data me ? o ? y 1 note z ? c ? ac ? ov ? sc add a ? x add i ?? ediate data to acc 1 z ? c ? ac ? ov ? sc adc a ? [ ? ] add data me ? o ? y to acc with ca ?? y 1 z ? c ? ac ? ov ? sc adcm a ? [ ? ] add acc to data ? e ? o ? y with ca ?? y 1 note z ? c ? ac ? ov ? sc sub a ? x su ? t ? a ? t i ?? ediate data f ? o ? the acc 1 z ? c ? ac ? ov ? sc ? cz sub a ? [ ? ] su ? t ? a ? t data me ? o ? y f ? o ? acc 1 z ? c ? ac ? ov ? sc ? cz subm a ? [ ? ] su ? t ? a ? t data me ? o ? y f ? o ? acc with ? esult in data me ? o ? y 1 note z ? c ? ac ? ov ? sc ? cz sbc a ? x su ? t ? a ? t i ?? ediate data f ? o ? acc with ca ?? y 1 z ? c ? ac ? ov ? sc ? cz sbc a ? [ ? ] su ? t ? a ? t data me ? o ? y f ? o ? acc with ca ?? y 1 z ? c ? ac ? ov ? sc ? cz sbcm a ? [ ? ] su ? t ? a ? t data me ? o ? y f ? o ? acc with ca ?? y ? ? esult in data me ? o ? y 1 note z ? c ? ac ? ov ? sc ? cz daa [ ? ] de ? i ? al adjust acc fo ? addition with ? esult in data me ? o ? y 1 note c logic operation and a ? [ ? ] logi ? al and data me ? o ? y to acc 1 z or a ? [ ? ] logi ? al or data me ? o ? y to acc 1 z xor a ? [ ? ] logi ? al xor data me ? o ? y to acc 1 z andm a ? [ ? ] logi ? al and acc to data me ? o ? y 1 note z orm a ? [ ? ] logi ? al or acc to data me ? o ? y 1 note z xorm a ? [ ? ] logi ? al xor acc to data me ? o ? y 1 note z and a ? x logi ? al and i ?? ediate data to acc 1 z or a ? x logi ? al or i ?? ediate data to acc 1 z xor a ? x logi ? al xor i ?? ediate data to acc 1 z cpl [ ? ] co ? ple ? ent data me ? o ? y 1 note z cpla [ ? ] co ? ple ? ent data me ? o ? y with ? esult in acc 1 z increment & decrement inca [ ? ] in ?? e ? ent data me ? o ? y with ? esult in acc 1 z inc [ ? ] in ?? e ? ent data me ? o ? y 1 note z deca [ ? ] de ?? e ? ent data me ? o ? y with ? esult in acc 1 z dec [ ? ] de ?? e ? ent data me ? o ? y 1 note z rotate rra [ ? ] rotate data me ? o ? y ? ight with ? esult in acc 1 none rr [ ? ] rotate data me ? o ? y ? ight 1 note none rrca [ ? ] rotate data me ? o ? y ? ight th ? ough ca ?? y with ? esult in acc 1 c rrc [ ? ] rotate data me ? o ? y ? ight th ? ough ca ?? y 1 note c rla [ ? ] rotate data me ? o ? y left with ? esult in acc 1 none rl [ ? ] rotate data me ? o ? y left 1 note none rlca [ ? ] rotate data me ? o ? y left th ? ough ca ?? y with ? esult in acc 1 c rlc [ ? ] rotate data me ? o ? y left th ? ough ca ?? y 1 note c
rev. 1.40 ?30 de?e??e? 1?? ?01? rev. 1.40 ? 31 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver mnemonic description cycles flag affected data move mov a ? [ ? ] move data me ? o ? y to acc 1 none mov [ ? ] ? a move acc to data me ? o ? y 1 note none mov a ? x move i ?? ediate data to acc 1 none bit operation clr [ ? ].i clea ? ? it of data me ? o ? y 1 note none set [ ? ].i set ? it of data me ? o ? y 1 note none branch operation jmp add ? ju ? p un ? onditionally ? none sz [ ? ] skip if data me ? o ? y is ze ? o 1 note none sza [ ? ] skip if data me ? o ? y is ze ? o with data ? ove ? ent to acc 1 note none sz [ ? ].i skip if ? it i of data me ? o ? y is ze ? o 1 note none snz [ ? ] skip if data me ? o ? y is not ze ? o 1 note none snz [ ? ].i skip if ? it i of data me ? o ? y is not ze ? o 1 note none siz [ ? ] skip if in ?? e ? ent data me ? o ? y is ze ? o 1 note none sdz [ ? ] skip if de ?? e ? ent data me ? o ? y is ze ? o 1 note none siza [ ? ] skip if in ?? e ? ent data me ? o ? y is ze ? o with ? esult in acc 1 note none sdza [ ? ] skip if de ?? e ? ent data me ? o ? y is ze ? o with ? esult in acc 1 note none call add ? su ?? outine ? all ? none ret retu ? n f ? o ? su ?? outine ? none ret a ? x retu ? n f ? o ? su ?? outine and load i ?? ediate data to acc ? none reti retu ? n f ? o ? inte ?? upt ? none table read operation tabrd [ ? ] read table (specifc page) to tblh and data memory ? note none tabrdl [ ? ] read ta ? le (last page) to tblh and data me ? o ? y ? note none itabrd [ ? ] increment table pointer tblp frst and read table to tblh and data memory ? note none itabrdl [ ? ] increment table pointer tblp frst and read table (last page) to tblh and data me ? o ? y ? note none miscellaneous nop no ope ? ation 1 none clr [ ? ] clea ? data me ? o ? y 1 note none set [ ? ] set data me ? o ? y 1 note none clr wdt clea ? wat ? hdog ti ? e ? 1 to ? pdf swap [ ? ] swap ni ?? les of data me ? o ? y 1 note none swapa [ ? ] swap ni ?? les of data me ? o ? y with ? esult in acc 1 none halt ente ? powe ? down ? ode 1 to ? pdf note: 1. for skip instructions, if the result of the comparison involves a skip then up to three cycles are required, if no skip takes place only one cycle is required. 2. any instruction which changes the contents of the pcl will also require 2 cycles for execution. 3. for the "clr wdt" instruction the t o and pdf fags may be af fected by the execution status. the t o and pdf fa gs a re c leared a fter t he "cl r w dt" i nstructions i s e xecuted. ot herwise t he t o a nd pdf fags remain unchanged.
rev. 1.40 ? 3 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?33 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver extended instruction set the extended instructions are used to support the full range address access for the data memory . when the accessed data memory is located in any data memory sections except sector 0, the extended instructi on can be used to access the data memory instead of using the indirect addressing access to improve the cpu frmware performance. mnemonic description cycles flag affected arithmetic ladd a ? [ ? ] add data me ? o ? y to acc ? z ? c ? ac ? ov ? sc laddm a ? [ ? ] add acc to data me ? o ? y ? note z ? c ? ac ? ov ? sc ladc a ? [ ? ] add data me ? o ? y to acc with ca ?? y ? z ? c ? ac ? ov ? sc ladcm a ? [ ? ] add acc to data ? e ? o ? y with ca ?? y ? note z ? c ? ac ? ov ? sc lsub a ? [ ? ] su ? t ? a ? t data me ? o ? y f ? o ? acc ? z ? c ? ac ? ov ? sc ? cz lsubm a ? [ ? ] su ? t ? a ? t data me ? o ? y f ? o ? acc with ? esult in data me ? o ? y ? note z ? c ? ac ? ov ? sc ? cz lsbc a ? [ ? ] su ? t ? a ? t data me ? o ? y f ? o ? acc with ca ?? y ? z ? c ? ac ? ov ? sc ? cz lsbcm a ? [ ? ] su ? t ? a ? t data me ? o ? y f ? o ? acc with ca ?? y ? ? esult in data me ? o ? y ? note z ? c ? ac ? ov ? sc ? cz ldaa [ ? ] de ? i ? al adjust acc fo ? addition with ? esult in data me ? o ? y ? note c logic operation land a ? [ ? ] logi ? al and data me ? o ? y to acc ? z lor a ? [ ? ] logi ? al or data me ? o ? y to acc ? z lxor a ? [ ? ] logi ? al xor data me ? o ? y to acc ? z landm a ? [ ? ] logi ? al and acc to data me ? o ? y ? note z lorm a ? [ ? ] logi ? al or acc to data me ? o ? y ? note z lxorm a ? [ ? ] logi ? al xor acc to data me ? o ? y ? note z lcpl [ ? ] co ? ple ? ent data me ? o ? y ? note z lcpla [ ? ] co ? ple ? ent data me ? o ? y with ? esult in acc ? z increment & decrement linca [ ? ] in ?? e ? ent data me ? o ? y with ? esult in acc ? z linc [ ? ] in ?? e ? ent data me ? o ? y ? note z ldeca [ ? ] de ?? e ? ent data me ? o ? y with ? esult in acc ? z ldec [ ? ] de ?? e ? ent data me ? o ? y ? note z rotate lrra [ ? ] rotate data me ? o ? y ? ight with ? esult in acc ? none lrr [ ? ] rotate data me ? o ? y ? ight ? note none lrrca [ ? ] rotate data me ? o ? y ? ight th ? ough ca ?? y with ? esult in acc ? c lrrc [ ? ] rotate data me ? o ? y ? ight th ? ough ca ?? y ? note c lrla [ ? ] rotate data me ? o ? y left with ? esult in acc ? none lrl [ ? ] rotate data me ? o ? y left ? note none lrlca [ ? ] rotate data me ? o ? y left th ? ough ca ?? y with ? esult in acc ? c lrlc [ ? ] rotate data me ? o ? y left th ? ough ca ?? y ? note c data move lmov a ? [ ? ] move data me ? o ? y to acc ? none lmov [ ? ] ? a move acc to data me ? o ? y ? note none bit operation lclr [ ? ].i clea ? ? it of data me ? o ? y ? note none lset [ ? ].i set ? it of data me ? o ? y ? note none
rev. 1.40 ?3? de?e??e? 1?? ?01? rev. 1.40 ? 33 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver mnemonic description cycles flag affected branch lsz [ ? ] skip if data me ? o ? y is ze ? o ? note none lsza [ ? ] skip if data me ? o ? y is ze ? o with data ? ove ? ent to acc ? note none lsnz [ ? ] skip if data me ? o ? y is not ze ? o ? note none lsz [ ? ].i skip if ? it i of data me ? o ? y is ze ? o ? note none lsnz [ ? ].i skip if ? it i of data me ? o ? y is not ze ? o ? note none lsiz [ ? ] skip if in ?? e ? ent data me ? o ? y is ze ? o ? note none lsdz [ ? ] skip if de ?? e ? ent data me ? o ? y is ze ? o ? note none lsiza [ ? ] skip if in ?? e ? ent data me ? o ? y is ze ? o with ? esult in acc ? note none lsdza [ ? ] skip if de ?? e ? ent data me ? o ? y is ze ? o with ? esult in acc ? note none table read ltabrd [ ? ] read ta ? le to tblh and data me ? o ? y 3 note none ltabrdl [ ? ] read ta ? le (last page) to tblh and data me ? o ? y 3 note none litabrd [ ? ] increment table pointer tblp frst and read table to tblh and data memory 3 note none litabrdl [ ? ] increment table pointer tblp frst and read table (last page) to tblh and data me ? o ? y 3 note none miscellaneous lclr [ ? ] clea ? data me ? o ? y ? note none lset [ ? ] set data me ? o ? y ? note none lswap [ ? ] swap ni ?? les of data me ? o ? y ? note none lswapa [ ? ] swap ni ?? les of data me ? o ? y with ? esult in acc ? none note: 1. for these extended skip instructions, if the result of the comparison involves a skip then up to four cycles are required, if no skip takes place two cycles is required. 2. any extended instruction which changes the contents of the pcl register will also require three cycles for execution.
rev. 1.40 ? 34 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?3? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver instruction defnition adc a,[m] add d ata m emory to a cc w ith carry description the c ontents o f t he s pecifed d ata m emory, a ccumulator a nd t he c arry f ag a re a dded. the re sult is s tored in t he a ccumulator. operation acc a cc + [ m] + c affected f ag(s) ov, z , a c, c , s c adcm a,[m] add a cc to d ata m emory w ith carry description the c ontents o f t he s pecifed d ata m emory, a ccumulator a nd t he c arry f ag a re a dded. the re sult is s tored in t he sp ecifed d ata m emory. operation [m] a cc + [ m] + c affected f ag(s) ov, z , a c, c , s c add a,[m] add d ata m emory t o a cc description the c ontents o f t he s pecifed d ata m emory a nd t he a ccumulator a re a dded. the re sult is s tored in t he a ccumulator. operation acc a cc + [ m] affected f ag(s) ov, z , a c, c , s c add a,x add im mediate data to a cc description the c ontents o f t he a ccumulator a nd t he s pecifed im mediate data a re a dded. the re sult is s tored in t he a ccumulator. operation acc a cc + x affected f ag(s) ov, z , a c, c , s c addm a,[m] add a cc to d ata m emory description the c ontents o f t he s pecifed d ata m emory a nd t he a ccumulator a re a dded. the re sult is s tored in t he sp ecifed d ata m emory. operation [m] a cc + [ m] affected f ag(s) ov, z , a c, c , s c and a,[m] logical a nd d ata m emory t o a cc description data i n t he a ccumulator a nd t he s pecifed d ata m emory p erform a b itwise l ogical a nd operation. t he re sult is s tored in t he a ccumulator. operation acc a cc a nd [ m] affected f ag(s) z and a,x logical a nd im mediate data to a cc description data i n t he a ccumulator a nd t he s pecifed im mediate data p erform a b it w ise l ogical a nd operation. t he re sult is s tored in t he a ccumulator. operation acc a cc a nd x affected f ag(s) z andm a,[m] logical a nd a cc to d ata m emory description data i n t he s pecifed d ata m emory a nd t he a ccumulator p erform a b itwise l ogical a nd operation. t he re sult is s tored in t he d ata m emory. operation [m] a cc and [ m] affected f ag(s) z
rev. 1.40 ?34 de?e??e? 1?? ?01? rev. 1.40 ? 3 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver call addr subroutine c all description unconditionally c alls a s ubroutine a t t he s pecifed a ddress. th e p rogram c ounter t hen increments b y 1 to o btain t he a ddress o f t he n ext i nstruction w hich i s t hen p ushed o nto t he stack. t he sp ecifed a ddress is t hen loaded a nd t he p rogram c ontinues e xecution f rom t his new a ddress. a s t his instruction re quires a n a dditional op eration, it is a t wo c ycle instruction. operation stack p rogram counter + 1 program c ounter a ddr affected f ag(s) none clr [m] clear d ata m emory description each b it o f t he s pecifed d ata m emory i s cl eared t o 0 . operation [m] 00h affected f ag(s) none clr [m].i clear bi t o f d ata m emory description bit i o f t he s pecifed d ata m emory i s cl eared t o 0 . operation [m].i 0 affected f ag(s) none clr wdt clear w atchdog t imer description the t o, p df f ags a nd t he w dt a re al l c leared. operation wdt cl eared to 0 pdf 0 affected f ag(s) to, p df cpl [m] complement d ata m emory description each b it of t he s pecifed d ata m emory i s l ogically complemented ( 1s complement). b its w hich previously c ontained a 1 a re c hanged to 0 a nd v ice v ersa. operation [m] [m] affected f ag(s) z cpla [m] complement d ata m emory w ith r esult i n a cc description each b it of t he s pecifed d ata m emory i s l ogically complemented ( 1s complement). b its w hich previously c ontained a 1 a re c hanged to 0 a nd v ice v ersa. th e c omplemented r esult i s s tored i n the a ccumulator a nd t he c ontents o f t he d ata m emory r emain u nchanged. operation acc [ m] affected f ag(s) z daa [m] decimal-adjust a cc f or addition w ith r esult i n d ata m emory description convert t he c ontents o f t he a ccumulator v alue to a b cd ( binary c oded d ecimal) v alue resulting f rom t he p revious a ddition o f t wo b cd v ariables. i f t he low n ibble is greater t han 9 or i f a c f ag i s s et, t hen a v alue o f 6 w ill b e a dded to t he l ow n ibble. o therwise t he l ow n ibble remains u nchanged. i f t he h igh n ibble i s g reater t han 9 o r i f t he c f ag i s s et, t hen a v alue o f 6 will b e a dded to t he h igh n ibble. e ssentially, t he decimal c onversion i s p erformed b y a dding 00h, 0 6h, 6 0h o r 6 6h depending o n t he a ccumulator a nd f ag c onditions. o nly t he c f ag may b e a ffected b y t his instruction w hich indicates t hat if t he o riginal b cd s um is greater t han 100, it al lows m ultiple p recision decimal a ddition. operation [m] a cc + 00h or [m] a cc + 06 h o r [m] a cc + 60h o r [m] a cc + 66h affected f ag(s) c
rev. 1.40 ? 3 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?37 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver dec [m] decrement d ata m emory description data i n t he s pecifed d ata m emory i s d ecremented b y 1 . operation [m] [ m] ? 1 affected f ag(s) z deca [m] decrement d ata m emory wi th r esult i n a cc description data in t he sp ecifed d ata m emory is d ecremented b y 1 . t he re sult is s tored in t he accumulator. th e c ontents o f t he d ata m emory r emain u nchanged. operation acc [ m] ? 1 affected f ag(s) z halt enter p ower down m ode description this i nstruction s tops t he p rogram e xecution a nd t urns o ff t he s ystem c lock. th e c ontents o f the d ata m emory a nd r egisters a re r etained. th e w dt a nd p rescaler a re c leared. th e p ower down f ag p df i s s et a nd t he w dt t ime-out f ag t o i s c leared. operation to 0 pdf 1 affected f ag(s) to, p df inc [m] increment d ata m emory description data in t he sp ecifed d ata m emory is incremented b y 1 . operation [m] [ m] + 1 affected f ag(s) z inca [m] increment d ata m emory wi th r esult i n a cc description data i n t he sp ecifed d ata m emory i s i ncremented b y 1 . th e re sult i s s tored i n t he a ccumulator. the c ontents o f t he d ata m emory r emain u nchanged. operation acc [ m] + 1 affected f ag(s) z jmp addr jump u nconditionally description the c ontents o f t he p rogram c ounter a re re placed w ith t he sp ecifed a ddress. p rogram execution t hen c ontinues f rom t his n ew a ddress. a s t his re quires t he insertion o f a d ummy instruction w hile t he n ew a ddress is loaded, it is a t wo c ycle instruction. operation program counter addr affected f ag(s) none mov a,[m] move d ata m emory t o a cc description the c ontents o f t he s pecifed d ata m emory a re c opied to t he a ccumulator. operation acc [ m] affected f ag(s) none mov a,x move im mediate data to a cc description the im mediate data s pecifed i s l oaded i nto t he a ccumulator. operation acc x affected f ag(s) none mov [m],a move a cc to d ata m emory description the c ontents o f t he a ccumulator a re c opied to t he s pecifed d ata m emory. operation [m] a cc affected f ag(s) none
rev. 1.40 ?3? de?e??e? 1?? ?01? rev. 1.40 ? 37 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver nop no o peration description no o peration i s p erformed. e xecution c ontinues w ith t he n ext i nstruction. operation no operation affected f ag(s) none or a,[m] logical o r d ata m emory to a cc description data i n t he a ccumulator a nd t he s pecifed d ata m emory p erform a b itwise logical o r op eration. t he re sult is s tored in t he a ccumulator. operation acc a cc or [ m] affected f ag(s) z or a,x logical or im mediate data to a cc description data i n t he a ccumulator a nd t he s pecifed im mediate data p erform a b itwise l ogical o r operation. t he re sult is s tored in t he a ccumulator. operation acc a cc or x affected f ag(s) z orm a,[m] logical or a cc to d ata m emory description data i n t he s pecifed d ata m emory a nd t he a ccumulator p erform a b itwise l ogical o r operation. t he re sult is s tored in t he d ata m emory. operation [m] a cc or [ m] affected f ag(s) z ret return from s ubroutine description the p rogram c ounter is re stored f rom t he s tack. p rogram e xecution c ontinues a t t he re stored a ddress. operation program counter s tack affected f ag(s) none ret a,x return f rom su broutine and l oad im mediate data to a cc description the p rogram c ounter i s r estored f rom t he s tack a nd t he a ccumulator l oaded w ith t he s pecifed immediate data. p rogram e xecution c ontinues a t t he r estored a ddress. operation program counter s tack acc x affected f ag(s) none reti return from i nterrupt description the p rogram c ounter is re stored f rom t he s tack a nd t he interrupts a re re -enabled b y s etting t he emi b it. e mi i s t he m aster i nterrupt g lobal e nable b it. i f a n i nterrupt w as p ending w hen t he reti instruction is e xecuted, t he p ending in terrupt ro utine w ill b e p rocessed b efore re turning to t he m ain p rogram. operation program counter s tack emi 1 affected f ag(s) none rl [m] rotate d ata m emory l eft description the c ontents o f t he s pecifed d ata m emory a re r otated l eft b y 1 b it w ith b it 7 r otated i nto b it 0 . operation [m].(i+1) [ m].i; (i=0~6) [m].0 [ m].7 affected f ag(s) none
rev. 1.40 ? 38 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?39 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver rla [m] rotate d ata m emory left w ith re sult in a cc description the c ontents o f t he s pecifed d ata m emory a re r otated l eft b y 1 b it w ith b it 7 r otated i nto b it 0 . the r otated r esult i s s tored i n t he a ccumulator a nd t he c ontents o f t he d ata m emory r emain u nchanged. operation acc.(i+1) [ m].i; (i=0~6) acc.0 [ m].7 affected f ag(s) none rlc [m] rotate d ata m emory l eft t hrough carry description the c ontents o f t he s pecifed d ata m emory a nd t he c arry f ag a re r otated l eft b y 1 b it. b it 7 replaces t he c arry b it a nd t he o riginal c arry f ag i s r otated i nto b it 0 . operation [m].(i+1) [ m].i; (i=0~6) [m].0 c c [ m].7 affected f ag(s) c rlca [m] rotate d ata m emory left t hrough c arry w ith re sult in a cc description data i n t he s pecifed d ata m emory and t he carry f ag are r otated l eft b y 1 b it. b it 7 r eplaces t he carry b it a nd t he o riginal c arry f ag i s r otated i nto t he b it 0 . th e r otated r esult i s s tored i n t he accumulator a nd t he c ontents o f t he d ata m emory r emain u nchanged. operation acc.(i+1) [ m].i; (i=0~6) acc.0 c c [ m].7 affected f ag(s) c rr [m] rotate d ata m emory r ight description the contents of t he s pecifed d ata m emory are r otated r ight b y 1 b it w ith b it 0 r otated i nto b it 7 . operation [m].i [ m].(i+1); (i=0~6) [m].7 [ m].0 affected f ag(s) none rra [m] rotate d ata m emory right with result i n a cc description data i n t he s pecifed d ata m emory a nd t he c arry f ag a re r otated r ight b y 1 b it w ith b it 0 rotated i nto b it 7 . th e r otated r esult i s s tored i n t he a ccumulator a nd t he c ontents o f t he data m emory r emain u nchanged. operation acc.i [ m].(i+1); (i=0~6) acc.7 [ m].0 affected f ag(s) none rrc [m] rotate d ata m emory r ight t hrough carry description the c ontents o f t he s pecifed d ata m emory a nd t he c arry f ag a re r otated r ight b y 1 b it. b it 0 replaces t he c arry b it a nd t he o riginal c arry f ag i s r otated i nto b it 7 . operation [m].i [ m].(i+1); (i=0~6) [m].7 c c [ m].0 affected f ag(s) c
rev. 1.40 ?38 de?e??e? 1?? ?01? rev. 1.40 ? 39 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver rrca [m] rotate d ata m emory right th rough c arry with result i n a cc description data i n t he s pecifed d ata m emory a nd t he c arry f ag a re r otated r ight b y 1 b it. b it 0 r eplaces the c arry b it a nd t he o riginal c arry f ag i s r otated i nto b it 7 . th e r otated r esult i s s tored i n t he accumulator a nd t he c ontents o f t he d ata m emory r emain u nchanged. operation acc.i [ m].(i+1); (i=0~6) acc.7 c c [ m].0 affected f ag(s) c sbc a,[m] subtract d ata m emory from a cc wi th c arry description the c ontents o f t he s pecifed d ata m emory a nd t he c omplement o f t he c arry f ag a re subtracted f rom t he a ccumulator. t he re sult is s tored in t he a ccumulator. n ote t hat if t he result o f s ubtraction is n egative, t he c f ag w ill b e c leared t o 0 , o therwise if t he re sult is positive o r z ero, t he c f ag w ill b e s et to 1 . operation acc a cc ? [ m] ? c affected f ag(s) ov, z , a c, c , s c, c z sbc a, x subtract im mediate data f rom a cc w ith carry description the immediate da ta a nd t he c omplement o f t he c arry f ag a re s ubtracted f rom t he accumulator. t he re sult is s tored in t he a ccumulator. n ote t hat if t he re sult o f s ubtraction is negative, t he c f ag w ill b e c leared t o 0 , o therwise if t he re sult is p ositive o r z ero, t he c f ag will be se t t o 1 . operation acc a cc - [ m] - c affected f ag(s) ov, z , ac , c , s c, cz sbcm a,[m] subtract d ata m emory from a cc wi th c arry a nd r esult i n d ata m emory description the c ontents o f t he s pecifed d ata m emory a nd t he c omplement o f t he c arry f ag a re subtracted f rom t he a ccumulator. t he re sult is s tored in t he d ata m emory. n ote t hat if t he result o f s ubtraction is n egative, t he c f ag w ill b e c leared t o 0 , o therwise if t he re sult is positive o r z ero, t he c f ag w ill b e s et to 1 . operation [m] a cc ? [ m] ? c affected f ag(s) ov, z , a c, c , s c, c z sdz [m] skip i f decrement d ata m emory i s 0 description the c ontents o f t he s pecifed d ata m emory a re fr st decremented b y 1 . i f t he r esult i s 0 t he following instruction is s kipped. a s t his re quires t he insertion o f a d ummy instruction w hile the n ext instruction is f etched, it is a t wo c ycle instruction. i f t he re sult is n ot 0 t he p rogram proceeds w ith t he f ollowing i nstruction. operation [m] [ m] ? 1 skip if [ m]=0 affected f ag(s) none sdza [m] skip i f decrement d ata m emory i s z ero w ith r esult i n a cc description the c ontents o f t he s pecifed d ata m emory a re fr st decremented b y 1 . i f t he r esult i s 0 , t he following instruction is s kipped. t he re sult is s tored in t he a ccumulator b ut t he sp ecifed data m emory c ontents r emain u nchanged. a s t his r equires t he i nsertion o f a dummy instruction w hile t he n ext instruction is f etched, it is a t wo c ycle instruction. i f t he r esult is n ot 0 , the p rogram p roceeds w ith t he f ollowing instruction. operation acc [ m] ? 1 skip if a cc=0 affected f ag(s) none
rev. 1.40 ? 40 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?41 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver set [m] set d ata m emory description each b it o f t he s pecifed d ata m emory i s s et t o 1 . operation [m] f fh affected f ag(s) none set [m].i set b it o f d ata m emory description bit i o f t he s pecifed d ata m emory i s s et t o 1 . operation [m].i 1 affected f ag(s) none siz [m] skip i f i ncrement d ata m emory i s 0 description the c ontents o f t he sp ecifed d ata m emory a re f rst incremented b y 1 . i f t he re sult is 0 , t he following instruction is s kipped. a s t his re quires t he insertion o f a d ummy instruction w hile the n ext instruction is f etched, it is a t wo c ycle instruction. i f t he re sult is n ot 0 t he p rogram proceeds w ith t he f ollowing i nstruction. operation [m] [ m] + 1 skip if [ m]=0 affected f ag(s) none siza [m] skip if increment d ata m emory is z ero w ith re sult in a cc description the c ontents o f t he sp ecifed d ata m emory a re f rst incremented b y 1 . i f t he re sult is 0 , t he following instruction is s kipped. t he re sult is s tored in t he a ccumulator b ut t he sp ecifed data m emory c ontents r emain u nchanged. a s t his r equires t he i nsertion o f a dummy instruction w hile t he n ext instruction is f etched, it is a t wo c ycle instruction. i f t he re sult is n ot 0 t he p rogram p roceeds w ith t he f ollowing instruction. operation acc [ m] + 1 skip if a cc=0 affected f ag(s) none snz [m].i skip i f d ata m emory i s no t 0 description if t he sp ecifed d ata m emory is n ot 0 , t he f ollowing instruction is s kipped. a s t his re quires t he insertion o f a d ummy instruction w hile t he n ext instruction is f etched, it is a t wo c ycle instruction. i f t he re sult is 0 t he p rogram p roceeds w ith t he f ollowing instruction. operation skip i f [ m].i 0 affected f ag(s) none snz [m] skip i f d ata m emory i s no t 0 description if t he sp ecifed d ata m emory is n ot 0 , t he f ollowing instruction is s kipped. a s t his re quires t he insertion o f a d ummy instruction w hile t he n ext instruction is f etched, it is a t wo c ycle instruction. i f t he re sult is 0 t he p rogram p roceeds w ith t he f ollowing instruction. operation skip i f [ m] 0 affected f ag(s) none sub a,[m] subtract d ata m emory from a cc description the s pecifed d ata m emory i s s ubtracted f rom t he c ontents o f t he a ccumulator. th e r esult i s stored in t he a ccumulator. n ote t hat if t he re sult o f s ubtraction is n egative, t he c f ag w ill b e cleared to 0 , o therwise i f t he r esult i s p ositive o r z ero, t he c f ag w ill b e s et to 1 . operation acc a cc ? [ m] affected f ag(s) ov, z , a c, c , s c, c z
rev. 1.40 ?40 de?e??e? 1?? ?01? rev. 1.40 ? 41 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver subm a,[m] subtract d ata m emory from a cc wi th r esult i n d ata m emory description the s pecifed d ata m emory i s s ubtracted f rom t he c ontents o f t he a ccumulator. th e r esult i s stored in t he d ata m emory. n ote t hat if t he re sult o f s ubtraction is n egative, t he c f ag w ill b e cleared to 0 , o therwise i f t he r esult i s p ositive o r z ero, t he c f ag w ill b e s et to 1 . operation [m] a cc ? [ m] affected f ag(s) ov, z , a c, c , s c, c z sub a,x subtract im mediate data f rom a cc description the im mediate data s pecifed b y t he c ode i s s ubtracted f rom t he c ontents o f t he a ccumulator. the re sult is s tored in t he a ccumulator. n ote t hat if t he re sult o f s ubtraction is n egative, t he c fag w ill b e c leared to 0 , o therwise i f t he r esult i s p ositive o r z ero, t he c f ag w ill b e s et to 1 . operation acc a cc ? x affected f ag(s) ov, z , a c, c , s c, c z swap [m] swap ni bbles of d ata m emory description the l ow-order a nd h igh-order n ibbles o f t he s pecifed d ata m emory a re i nterchanged. operation [m].3~[m].0 ? [ m].7~[m].4 affected f ag(s) none swapa [m] swap ni bbles of d ata m emory w ith r esult i n a cc description the l ow-order a nd h igh-order n ibbles o f t he s pecifed d ata m emory a re i nterchanged. th e result i s s tored i n t he a ccumulator. th e c ontents o f t he d ata m emory r emain u nchanged. operation acc.3~acc.0 [ m].7~[m].4 acc.7~acc.4 [ m].3~[m].0 affected f ag(s) none sz [m] skip i f d ata m emory i s 0 description if t he contents of t he s pecifed d ata m emory i s 0, t he following i nstruction i s s kipped. a s t his requires t he insertion o f a d ummy instruction w hile t he n ext instruction is f etched, it is a t wo cycle instruction. i f t he re sult is n ot 0 t he p rogram p roceeds w ith t he f ollowing instruction. operation skip if [ m]=0 affected f ag(s) none sza [m] skip i f d ata m emory i s 0 w ith data m ovement to a cc description the c ontents o f t he s pecifed d ata m emory a re c opied to t he a ccumulator. i f t he v alue i s z ero, the f ollowing instruction is s kipped. a s t his re quires t he insertion o f a d ummy instruction while t he n ext instruction is f etched, it is a t wo c ycle instruction. i f t he re sult is n ot 0 t he program p roceeds w ith t he f ollowing instruction. operation acc [ m] skip if [ m]=0 affected f ag(s) none sz [m].i skip i f b it i of d ata m emory i s 0 description if b it i o f t he sp ecifed d ata m emory is 0 , t he f ollowing instruction is s kipped. a s t his re quires the insertion o f a d ummy instruction w hile t he n ext instruction is f etched, it is a t wo c ycle instruction. i f t he re sult is n ot 0 , t he p rogram p roceeds w ith t he f ollowing instruction. operation skip if [ m].i=0 affected f ag(s) none
rev. 1.40 ? 4 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?43 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver tabrd [m] read ta ble ( specifc p age) to t blh a nd d ata m emory description the low b yte o f t he p rogram c ode ( specifc p age) a ddressed b y t he t able p ointer p air (tblp a nd t bhp) i s mo ved t o t he s pecifed d ata m emory a nd t he h igh by te mo ved t o t blh. operation [m] pr ogram c ode (low by te) tblh pr ogram c ode (high by te) affected f ag(s) none tabrdl [m] read t able (last p age) t o t blh a nd d ata m emory description the l ow by te o f t he pr ogram c ode (last p age) a ddressed by t he t able p ointer (tblp) i s mo ved to t he s pecifed d ata m emory a nd t he h igh b yte m oved to t blh. operation [m] pr ogram c ode (low by te) tblh pr ogram c ode (high by te) affected f ag(s) none itabrd [m] increment ta ble p ointer l ow b yte fr st and r ead ta ble to t blh and d ata m emory description increment ta ble p ointer l ow b yte, t blp, fr st and t hen t he p rogram code addressed b y t he table p ointer ( tbhp and t blp) i s m oved to t he s pecifed d ata m emory and t he hi gh b yte moved t o t blh. operation [m] pr ogram c ode (low by te) tblh pr ogram c ode (high by te) affected f ag(s) none itabrdl [m] increment t able p ointer l ow by te f rst a nd r ead t able (last p age) t o t blh a nd d ata m emory description increment ta ble p ointer l ow b yte, t blp, fr st and t hen t he l ow b yte of t he p rogram code (last p age) addressed b y t he ta ble p ointer ( tblp) i s m oved to t he s pecifed d ata m emory and the h igh by te mov ed t o t blh. operation [m] pr ogram c ode (low by te) tblh pr ogram c ode (high by te) affected f ag(s) none xor a,[m] logical x or d ata m emory to a cc description data i n t he a ccumulator a nd t he s pecifed d ata m emory p erform a b itwise l ogical x or operation. t he re sult is s tored in t he a ccumulator. operation acc a cc x or [ m] affected f ag(s) z xorm a,[m] logical x or a cc to d ata m emory description data i n t he s pecifed d ata m emory a nd t he a ccumulator p erform a b itwise l ogical x or operation. t he re sult is s tored in t he d ata m emory. operation [m] a cc xor [ m] affected f ag(s) z xor a,x logical x or im mediate data to a cc description data i n t he a ccumulator a nd t he s pecifed im mediate data p erform a b itwise l ogical x or operation. t he re sult is s tored in t he a ccumulator. operation acc a cc x or x affected f ag(s) z
rev. 1.40 ?4? de?e??e? 1?? ?01? rev. 1.40 ? 43 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver extended instruction defnition the extended instructions are used to directly access the data stored in any data memory sections. ladc a,[m] add d ata m emory to a cc w ith carry description the c ontents o f t he s pecifed d ata m emory, a ccumulator a nd t he c arry f ag a re a dded. the re sult is s tored in t he a ccumulator. operation acc a cc + [ m] + c affected f ag(s) ov, z , a c, c , s c ladcm a,[m] add a cc to d ata m emory w ith carry description the c ontents o f t he s pecifed d ata m emory, a ccumulator a nd t he c arry f ag a re a dded. the re sult is s tored in t he sp ecifed d ata m emory. operation [m] a cc + [ m] + c affected f ag(s) ov, z , a c, c , s c ladd a,[m] add d ata m emory t o a cc description the c ontents o f t he s pecifed d ata m emory a nd t he a ccumulator a re a dded. the re sult is s tored in t he a ccumulator. operation acc a cc + [ m] affected f ag(s) ov, z , a c, c , s c laddm a,[m] add a cc to d ata m emory description the c ontents o f t he s pecifed d ata m emory a nd t he a ccumulator a re a dded. the re sult is s tored in t he sp ecifed d ata m emory. operation [m] a cc + [ m] affected f ag(s) ov, z , a c, c , s c land a,[m] logical a nd d ata m emory t o a cc description data i n t he a ccumulator a nd t he s pecifed d ata m emory p erform a b itwise l ogical a nd operation. t he re sult is s tored in t he a ccumulator. operation acc a cc a nd [ m] affected f ag(s) z landm a,[m] logical a nd a cc to d ata m emory description data i n t he s pecifed d ata m emory a nd t he a ccumulator p erform a b itwise l ogical a nd operation. t he re sult is s tored in t he d ata m emory. operation [m] a cc and [ m] affected f ag(s) z lclr [m] clear d ata m emory description each b it o f t he s pecifed d ata m emory i s cl eared t o 0 . operation [m] 00h affected f ag(s) none lclr [m].i clear bi t o f d ata m emory description bit i o f t he s pecifed d ata m emory i s cl eared t o 0 . operation [m].i 0 affected f ag(s) none
rev. 1.40 ? 44 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?4? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver lcpl [m] complement d ata m emory description each b it of t he s pecifed d ata m emory i s l ogically complemented ( 1s complement). b its w hich previously c ontained a 1 a re c hanged to 0 a nd v ice v ersa. operation [m] [m] affected f ag(s) z lcpla [m] complement d ata m emory w ith r esult i n a cc description each b it of t he s pecifed d ata m emory i s l ogically complemented ( 1s complement). b its w hich previously c ontained a 1 a re c hanged to 0 a nd v ice v ersa. th e c omplemented r esult i s s tored i n the a ccumulator a nd t he c ontents o f t he d ata m emory r emain u nchanged. operation acc [ m] affected f ag(s) z ldaa [m] decimal-adjust a cc f or addition w ith r esult i n d ata m emory description convert t he c ontents o f t he a ccumulator v alue to a b cd ( binary c oded d ecimal) v alue resulting f rom t he p revious a ddition o f t wo b cd v ariables. i f t he low n ibble is greater t han 9 or i f a c f ag i s s et, t hen a v alue o f 6 w ill b e a dded to t he l ow n ibble. o therwise t he l ow n ibble remains u nchanged. i f t he h igh n ibble i s g reater t han 9 o r i f t he c f ag i s s et, t hen a v alue o f 6 will b e a dded to t he h igh n ibble. e ssentially, t he decimal c onversion i s p erformed b y a dding 00h, 0 6h, 6 0h o r 6 6h depending o n t he a ccumulator a nd f ag c onditions. o nly t he c f ag may b e a ffected b y t his instruction w hich indicates t hat if t he o riginal b cd s um is greater t han 100, it al lows m ultiple p recision decimal a ddition. operation [m] a cc + 00h or [m] a cc + 06 h o r [m] a cc + 60h o r [m] a cc + 66h affected f ag(s) c ldec [m] decrement d ata m emory description data i n t he s pecifed d ata m emory i s d ecremented b y 1 . operation [m] [ m] ? 1 affected f ag(s) z ldeca [m] decrement d ata m emory wi th r esult i n a cc description data in t he sp ecifed d ata m emory is d ecremented b y 1 . t he re sult is s tored in t he accumulator. th e c ontents o f t he d ata m emory r emain u nchanged. operation acc [ m] ? 1 affected f ag(s) z linc [m] increment d ata m emory description data in t he sp ecifed d ata m emory is incremented b y 1 . operation [m] [ m] + 1 affected f ag(s) z linca [m] increment d ata m emory wi th r esult i n a cc description data i n t he sp ecifed d ata m emory i s i ncremented b y 1 . th e re sult i s s tored i n t he a ccumulator. the c ontents o f t he d ata m emory r emain u nchanged. operation acc [ m] + 1 affected f ag(s) z
rev. 1.40 ?44 de?e??e? 1?? ?01? rev. 1.40 ? 4 ? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver lmov a,[m] move d ata m emory t o a cc description the c ontents o f t he s pecifed d ata m emory a re c opied to t he a ccumulator. operation acc [ m] affected f ag(s) none lmov [m],a move a cc to d ata m emory description the c ontents o f t he a ccumulator a re c opied to t he s pecifed d ata m emory. operation [m] a cc affected f ag(s) none lor a,[m] logical o r d ata m emory to a cc description data i n t he a ccumulator a nd t he s pecifed d ata m emory p erform a b itwise logical o r op eration. t he re sult is s tored in t he a ccumulator. operation acc a cc or [ m] affected f ag(s) z lorm a,[m] logical or a cc to d ata m emory description data i n t he s pecifed d ata m emory a nd t he a ccumulator p erform a b itwise l ogical o r operation. t he re sult is s tored in t he d ata m emory. operation [m] a cc or [ m] affected f ag(s) z lrl [m] rotate d ata m emory l eft description the c ontents o f t he s pecifed d ata m emory a re r otated l eft b y 1 b it w ith b it 7 r otated i nto b it 0 . operation [m].(i+1) [ m].i; (i=0~6) [m].0 [ m].7 affected f ag(s) none lrla [m] rotate d ata m emory left w ith re sult in a cc description the c ontents o f t he s pecifed d ata m emory a re r otated l eft b y 1 b it w ith b it 7 r otated i nto b it 0 . the r otated r esult i s s tored i n t he a ccumulator a nd t he c ontents o f t he d ata m emory r emain u nchanged. operation acc.(i+1) [ m].i; (i=0~6) acc.0 [ m].7 affected f ag(s) none lrlc [m] rotate d ata m emory l eft t hrough carry description the c ontents o f t he s pecifed d ata m emory a nd t he c arry f ag a re r otated l eft b y 1 b it. b it 7 replaces t he c arry b it a nd t he o riginal c arry f ag i s r otated i nto b it 0 . operation [m].(i+1) [ m].i; (i=0~6) [m].0 c c [ m].7 affected f ag(s) c lrlca [m] rotate d ata m emory left t hrough c arry w ith re sult in a cc description data i n t he s pecifed d ata m emory and t he carry f ag are r otated l eft b y 1 b it. b it 7 r eplaces t he carry b it a nd t he o riginal c arry f ag i s r otated i nto t he b it 0 . th e r otated r esult i s s tored i n t he accumulator a nd t he c ontents o f t he d ata m emory r emain u nchanged. operation acc.(i+1) [ m].i; (i=0~6) acc.0 c c [ m].7 affected f ag(s) c
rev. 1.40 ? 4 ? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?47 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver lrr [m] rotate d ata m emory r ight description the contents of t he s pecifed d ata m emory are r otated r ight b y 1 b it w ith b it 0 r otated i nto b it 7 . operation [m].i [ m].(i+1); (i=0~6) [m].7 [ m].0 affected f ag(s) none lrra [m] rotate d ata m emory right with result i n a cc description data i n t he s pecifed d ata m emory a nd t he c arry f ag a re r otated r ight b y 1 b it w ith b it 0 rotated i nto b it 7 . th e r otated r esult i s s tored i n t he a ccumulator a nd t he c ontents o f t he data m emory r emain u nchanged. operation acc.i [ m].(i+1); (i=0~6) acc.7 [ m].0 affected f ag(s) none lrrc [m] rotate d ata m emory r ight t hrough carry description the c ontents o f t he s pecifed d ata m emory a nd t he c arry f ag a re r otated r ight b y 1 b it. b it 0 replaces t he c arry b it a nd t he o riginal c arry f ag i s r otated i nto b it 7 . operation [m].i [ m].(i+1); (i=0~6) [m].7 c c [ m].0 affected f ag(s) c lrrca [m] rotate d ata m emory right th rough c arry with result i n a cc description data i n t he s pecifed d ata m emory a nd t he c arry f ag a re r otated r ight b y 1 b it. b it 0 r eplaces the c arry b it a nd t he o riginal c arry f ag i s r otated i nto b it 7 . th e r otated r esult i s s tored i n t he accumulator a nd t he c ontents o f t he d ata m emory r emain u nchanged. operation acc.i [ m].(i+1); (i=0~6) acc.7 c c [ m].0 affected f ag(s) c lsbc a,[m] subtract d ata m emory from a cc wi th c arry description the c ontents o f t he s pecifed d ata m emory a nd t he c omplement o f t he c arry f ag a re subtracted f rom t he a ccumulator. t he re sult is s tored in t he a ccumulator. n ote t hat if t he result o f s ubtraction is n egative, t he c f ag w ill b e c leared t o 0 , o therwise if t he re sult is positive o r z ero, t he c f ag w ill b e s et to 1 . operation acc a cc ? [ m] ? c affected f ag(s) ov, z , a c, c , s c, c z lsbcm a,[m] subtract d ata m emory from a cc wi th c arry a nd r esult i n d ata m emory description the c ontents o f t he s pecifed d ata m emory a nd t he c omplement o f t he c arry f ag a re subtracted f rom t he a ccumulator. t he re sult is s tored in t he d ata m emory. n ote t hat if t he result o f s ubtraction is n egative, t he c f ag w ill b e c leared t o 0 , o therwise if t he re sult is positive o r z ero, t he c f ag w ill b e s et to 1 . operation [m] a cc ? [ m] ? c affected f ag(s) ov, z , a c, c , s c, c z
rev. 1.40 ?4? de?e??e? 1?? ?01? rev. 1.40 ? 47 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver lsdz [m] skip i f decrement d ata m emory i s 0 description the c ontents o f t he s pecifed d ata m emory a re fr st decremented b y 1 . i f t he r esult i s 0 t he following instruction is s kipped. a s t his re quires t he insertion o f a d ummy instruction w hile the n ext instruction is f etched, it is a t wo c ycle instruction. i f t he re sult is n ot 0 t he p rogram proceeds w ith t he f ollowing i nstruction. operation [m] [ m] ? 1 skip if [ m]=0 affected f ag(s) none lsdza [m] skip i f decrement d ata m emory i s z ero w ith r esult i n a cc description the c ontents o f t he s pecifed d ata m emory a re fr st decremented b y 1 . i f t he r esult i s 0 , t he following instruction is s kipped. t he re sult is s tored in t he a ccumulator b ut t he sp ecifed data m emory c ontents r emain u nchanged. a s t his r equires t he i nsertion o f a dummy instruction w hile t he n ext instruction is f etched, it is a t wo c ycle instruction. i f t he r esult is n ot 0 , the p rogram p roceeds w ith t he f ollowing instruction. operation acc [ m] ? 1 skip if a cc=0 affected f ag(s) none lset [m] set d ata m emory description each b it o f t he s pecifed d ata m emory i s s et t o 1 . operation [m] f fh affected f ag(s) none lset [m].i set b it o f d ata m emory description bit i o f t he s pecifed d ata m emory i s s et t o 1 . operation [m].i 1 affected f ag(s) none lsiz [m] skip i f i ncrement d ata m emory i s 0 description the c ontents o f t he sp ecifed d ata m emory a re f rst incremented b y 1 . i f t he re sult is 0 , t he following instruction is s kipped. a s t his re quires t he insertion o f a d ummy instruction w hile the n ext instruction is f etched, it is a t wo c ycle instruction. i f t he re sult is n ot 0 t he p rogram proceeds w ith t he f ollowing i nstruction. operation [m] [ m] + 1 skip if [ m]=0 affected f ag(s) none lsiza [m] skip if increment d ata m emory is z ero w ith re sult in a cc description the c ontents o f t he sp ecifed d ata m emory a re f rst incremented b y 1 . i f t he re sult is 0 , t he following instruction is s kipped. t he re sult is s tored in t he a ccumulator b ut t he sp ecifed data m emory c ontents r emain u nchanged. a s t his r equires t he i nsertion o f a dummy instruction w hile t he n ext instruction is f etched, it is a t wo c ycle instruction. i f t he re sult is n ot 0 t he p rogram p roceeds w ith t he f ollowing instruction. operation acc [ m] + 1 skip if a cc=0 affected f ag(s) none lsnz [m].i skip i f d ata m emory i s no t 0 description if t he sp ecifed d ata m emory is n ot 0 , t he f ollowing instruction is s kipped. a s t his re quires t he insertion o f a d ummy instruction w hile t he n ext instruction is f etched, it is a t wo c ycle instruction. i f t he re sult is 0 t he p rogram p roceeds w ith t he f ollowing instruction. operation skip i f [ m].i 0 affected f ag(s) none
rev. 1.40 ? 48 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ?49 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver lsnz [m] skip i f d ata m emory i s no t 0 description if t he c ontent o f t he sp ecifed d ata m emory is n ot 0 , t he f ollowing instruction is s kipped. a s this re quires t he insertion o f a d ummy instruction w hile t he n ext instruction is f etched, it is a two c ycle instruction. i f t he re sult is 0 t he p rogram p roceeds w ith t he f ollowing instruction. operation skip i f [ m] 0 affected f ag(s) none lsub a,[m] subtract d ata m emory from a cc description the s pecifed d ata m emory i s s ubtracted f rom t he c ontents o f t he a ccumulator. th e r esult i s stored in t he a ccumulator. n ote t hat if t he re sult o f s ubtraction is n egative, t he c f ag w ill b e cleared to 0 , o therwise i f t he r esult i s p ositive o r z ero, t he c f ag w ill b e s et to 1 . operation acc a cc ? [ m] affected f ag(s) ov, z , a c, c , s c, c z lsubm a,[m] subtract d ata m emory from a cc wi th r esult i n d ata m emory description the s pecifed d ata m emory i s s ubtracted f rom t he c ontents o f t he a ccumulator. th e r esult i s stored in t he d ata m emory. n ote t hat if t he re sult o f s ubtraction is n egative, t he c f ag w ill b e cleared to 0 , o therwise i f t he r esult i s p ositive o r z ero, t he c f ag w ill b e s et to 1 . operation [m] a cc ? [ m] affected f ag(s) ov, z , a c, c , s c, c z lswap [m] swap ni bbles of d ata m emory description the l ow-order a nd h igh-order n ibbles o f t he s pecifed d ata m emory a re i nterchanged. operation [m].3~[m].0 ? [ m].7~[m].4 affected f ag(s) none lswapa [m] swap ni bbles of d ata m emory w ith r esult i n a cc description the l ow-order a nd h igh-order n ibbles o f t he s pecifed d ata m emory a re i nterchanged. th e result i s s tored i n t he a ccumulator. th e c ontents o f t he d ata m emory r emain u nchanged. operation acc.3~acc.0 [ m].7~[m].4 acc.7~acc.4 [ m].3~[m].0 affected f ag(s) none lsz [m] skip i f d ata m emory i s 0 description if t he contents of t he s pecifed d ata m emory i s 0, t he following i nstruction i s s kipped. a s t his requires t he insertion o f a d ummy instruction w hile t he n ext instruction is f etched, it is a t wo cycle instruction. i f t he re sult is n ot 0 t he p rogram p roceeds w ith t he f ollowing instruction. operation skip if [ m]=0 affected f ag(s) none lsza [m] skip i f d ata m emory i s 0 w ith data m ovement to a cc description the c ontents o f t he s pecifed d ata m emory a re c opied to t he a ccumulator. i f t he v alue i s z ero, the f ollowing instruction is s kipped. a s t his re quires t he insertion o f a d ummy instruction while t he n ext instruction is f etched, it is a t wo c ycle instruction. i f t he re sult is n ot 0 t he program p roceeds w ith t he f ollowing instruction. operation acc [ m] skip if [ m]=0 affected f ag(s) none
rev. 1.40 ?48 de?e??e? 1?? ?01? rev. 1.40 ? 49 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver lsz [m].i skip i f b it i of d ata m emory i s 0 description if b it i o f t he sp ecifed d ata m emory is 0 , t he f ollowing instruction is s kipped. a s t his re quires the insertion o f a d ummy instruction w hile t he n ext instruction is f etched, it is a t wo c ycle instruction. i f t he re sult is n ot 0 , t he p rogram p roceeds w ith t he f ollowing instruction. operation skip if [ m].i=0 affected f ag(s) none ltabrd [m] read ta ble ( current p age) to t blh a nd d ata m emory description the low b yte o f t he p rogram c ode ( current p age) a ddressed b y t he t able p ointer ( tblp) is moved t o t he s pecifed d ata m emory a nd t he h igh by te mo ved t o t blh. operation [m] pr ogram c ode (low by te) tblh pr ogram c ode (high by te) affected f ag(s) none ltabrdl [m] read t able (last p age) t o t blh a nd d ata m emory description the l ow by te o f t he pr ogram c ode (last p age) a ddressed by t he t able p ointer (tblp) i s mo ved to t he s pecifed d ata m emory a nd t he h igh b yte m oved to t blh. operation [m] pr ogram c ode (low by te) tblh pr ogram c ode (high by te) affected f ag(s) none litabrd [m] increment ta ble p ointer l ow b yte fr st and r ead ta ble to t blh and d ata m emory description increment ta ble p ointer l ow b yte, t blp, fr st and t hen t he p rogram code addressed b y t he table p ointer ( tbhp and t blp) i s m oved to t he s pecifed d ata m emory and t he hi gh b yte moved t o t blh. operation [m] pr ogram c ode (low by te) tblh pr ogram c ode (high by te) affected f ag(s) none litabrdl [m] increment t able p ointer l ow by te f rst a nd r ead t able (last p age) t o t blh a nd d ata m emory description increment ta ble p ointer l ow b yte, t blp, fr st and t hen t he l ow b yte of t he p rogram code (last p age) addressed b y t he ta ble p ointer ( tblp) i s m oved to t he s pecifed d ata m emory and the h igh by te mov ed t o t blh. operation [m] pr ogram c ode (low by te) tblh pr ogram c ode (high by te) affected f ag(s) none lxor a,[m] logical x or d ata m emory to a cc description data i n t he a ccumulator a nd t he s pecifed d ata m emory p erform a b itwise l ogical x or operation. t he re sult is s tored in t he a ccumulator. operation acc a cc x or [ m] affected f ag(s) z lxorm a,[m] logical x or a cc to d ata m emory description data i n t he s pecifed d ata m emory a nd t he a ccumulator p erform a b itwise l ogical x or operation. t he re sult is s tored in t he d ata m emory. operation [m] a cc xor [ m] affected f ag(s) z
rev. 1.40 ?? 0 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ??1 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver package information note that the package information provided here is for consultation purposes only . as this information may be updated at regular intervals users are reminded to consult the holtek website for the latest version of the package/carton information . additional supplementary information with regard to pa ckaging is listed below. click on the relevant section to be transferred to the relevant website page. ? further package information (include outline dimensions, product t ape and reel specifcations) ? packing meterials information ? carton information
rev. 1.40 ??0 de?e??e? 1?? ?01? rev. 1.40 ?? 1 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver 28-pin sop (300mil) outline dimensions               symbol dimensions in inch min. nom. max. a 0.40 ? bsc b 0. ? 9 ? bsc c 0.01 ? 0.0 ? 0 c 0.70 ? bsc d 0.104 e 0.0 ? 0 bsc f 0.004 0.01 ? g 0.01 ? 0.0 ? 0 h 0.008 0.013 0 D 8 symbol dimensions in mm min. nom. max. a 10.300 bsc b 7. ? 00 bsc c 0.31 0. ? 1 c 17.900 bsc d ? . ?? e 1. ? 70 bsc f 0.10 0.30 g 0.40 1. ? 7 h 0. ? 0 0.33 0 D 8
rev. 1.40 ??? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ??3 de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver 28-pin ssop (150mil) outline dimensions               symbol dimensions in inch min. nom. max. a 0. ? 3 ? bsc b 0.1 ? 4 bsc c 0.008 0.01 ? c 0.390 bsc d 0.0 ? 9 e 0.0 ?? bsc f 0.004 0.0098 g 0.01 ? 0.0 ? 0 h 0.004 0.010 0 8 symbol dimensions in mm min. nom. max. a ? .0 bsc b 3.9 bsc c 0. ? 0 0.30 c 9.9 bsc d 1.7 ? e 0. ? 3 ? bsc f 0.10 0. ?? g 0.41 1. ? 7 h 0.10 0. ?? 0 8
rev. 1.40 ??? de?e??e? 1?? ?01? rev. 1.40 ?? 3 de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver 44-pin lqfp (10mm10mm) (fp2.0mm) outline dimensions                     symbol dimensions in inch min. nom. max. a 0.47 ? bsc b 0.394 bsc c 0.47 ? bsc d 0.394 bsc e 0.03 ? bsc f 0.01 ? 0.01 ? 0.018 g 0.0 ? 3 0.0 ?? 0.0 ? 7 h 0.0 ? 3 i 0.00 ? 0.00 ? j 0.018 0.0 ? 4 0.030 k 0.004 0.008 0 7 symbol dimensions in mm min. nom. max. a 1 ? .00 bsc b 10.00 bsc c 1 ? .00 bsc d 10.00 bsc e 0.80 bsc f 0.30 0.37 0.4 ? g 1.3 ? 1.40 1.4 ? h 1. ? 0 i 0.0 ? 0.1 ? j 0.4 ? 0. ? 0 0.7 ? k 0.09 0. ? 0 0 7
rev. 1.40 ?? 4 de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 ??? de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver 48-pin lqfp (7mm7mm) outline dimensions                    symbol dimensions in inch min. nom. max. a 0.3 ? 4 bsc b 0. ? 7 ? bsc c 0.3 ? 4 bsc d 0. ? 7 ? bsc e 0.0 ? 0 bsc f 0.007 0.009 0.011 g 0.0 ? 3 0.0 ?? 0.0 ? 7 h 0.0 ? 3 i 0.00 ? 0.00 ? j 0.018 0.0 ? 4 0.030 k 0.004 D 0.008 0 D 7 symbol dimensions in mm min. nom. max. a 9.00 bsc b 7.00 bsc c 9.00 bsc d 7.00 bsc e 0. ? 0 bsc f 0.17 0. ?? 0. ? 7 g 1.3 ? 1.40 1.4 ? h 1. ? 0 i 0.0 ? 0.1 ? j 0.4 ? 0. ? 0 0.7 ? k 0.09 0. ? 0 0 D 7
rev. 1.40 ??4 de?e??e? 1?? ?01? rev. 1.40 ??? de ? e ?? e ? 1 ?? ? 01 ? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver 64-pin lqfp (7mm7mm) outline dimensions                    symbol dimensions in inch min. nom. max. a 0.3 ? 4 bsc b 0. ? 7 ? bsc c 0.3 ? 4 bsc d 0. ? 7 ? bsc e 0.01 ? bsc f 0.00 ? 0.007 0.009 g 0.0 ? 3 0.0 ?? 0.0 ? 7 h 0.0 ? 3 i 0.00 ? 0.00 ? j 0.018 0.0 ? 4 0.030 k 0.004 0.008 0 7 symbol dimensions in mm min. nom. max. a 9.00 bsc b 7.00 bsc c 9.00 bsc d 7.00 bsc e 0.40 bsc f 0.13 0.18 0. ? 3 g 1.3 ? 1.40 1.4 ? h 1. ? 0 i 0.0 ? 0.1 ? j 0.4 ? 0. ? 0 0.7 ? k 0.09 0. ? 0 0 7
rev. 1.40 ??? de ? e ?? e ? 1 ?? ? 01 ? rev. 1.40 pb de?e??e? 1?? ?01? bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver bs66f340/bs66f350/BS66F360/bs66f370 enhanced touch a/d flash mcu with led driver copy ? ight ? ? 01 ? ? y holtek semiconductor inc. the info ?? ation appea ? ing in this data sheet is ? elieved to ? e a ?? u ? ate at the ti ? e of pu ? li ? ation. howeve ?? holtek assu ? es no ? esponsi ? ility a ? ising f ? o ? the use of the specifcations described. the applications mentioned herein are used solely fo ? the pu ? pose of illust ? ation and holtek ? akes no wa ?? anty o ? ? ep ? esentation that su ? h appli ? ations will ? e suita ? le without fu ? the ? ? odifi ? ation ? no ? ? e ? o ?? ends the use of its p ? odu ? ts fo ? appli ? ation that ? ay p ? esent a ? isk to hu ? an life due to ? alfun ? tion o ? othe ? wise. holtek's p ? odu ? ts a ? e not autho ? ized fo ? use as ?? iti ? al ? o ? ponents in life suppo ? t devi ? es o ? syste ? s. holtek ? ese ? ves the ? ight to alte ? its products without prior notifcation. for the most up-to-date information, please visit ou ? we ? site at http://www.holtek. ? o ? .tw.


▲Up To Search▲   

 
Price & Availability of BS66F360

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