Home
78K0S/Kx1+ Sample Program (8-bit Timer 80) Interval Timer AN
Contents
1. cere eee 10 4 1 Setting the Interval Timer Function of 8 bit Timer 80 10 4 2 Setting the LED Blinking Cycle and Chattering Detection Time 16 CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM 20 5 1 Building the Sample Program eee eee eee een 20 De Operauon M S MEP s aa eerte pe prol deat Godd aset o dcs s oco P dau 22 CHAPTER 6 RELATED DOCUMENTS ooeeeeeeeee eee eee nene nenene 26 APPENDIX A PROGRAM LIST zao e kase RE ORE uS na n eR x Ra K KA xe NSR SSUASSE 27 APPENDIX B REVISION HISTORY aoi suspen uh ero er oen aea a nae x02 Hbes eun EM SHS AASNKA Ka 39 e The information in this document is current as of July 2008 The information is subject to change without notice For actual design in refer to the latest publications of NEC Electronics data sheets or data books etc for the most up to date specifications of NEC Electronics products Not all products and or types are available in every country Please check with an NEC Electronics sales representative for availability and additional information e No part of this document may be copied or reproduced in any form or by any means without the prior written consent of NEC Electronics NEC Electronics assumes no responsibility for any errors that may appear in this document e NEC Electronics does not assume any liability for infringement of patents copyrights or other intellectual proper
2. K S E u n Z B aj o u en o a oc ES a ae raj a a up i oje p Mao p ho o O i a oh Initialize the port 12 Z tin oC ao P U ec Ad A S a Ono Ne C Do S C S A o o ESEE EEA x Plz 0500000000 Set output latch s of P120 P123 as low NI PM12 0b11110000 Zk Set P120 P125 as output mode p e EE E a fa pa ne A E k as E o pe E E oan E pa DD lowes Sa EEE Initialize the port 13 P DECEPTUM x P13 0b00000001 S Set output datech of P130 as nigh y E M T E Set 8 bit timer 80 EE N E E E E E A ES EE E E RENE E E DEE EEE NU REC E ER x TMC80 0b00000000 Z Count Clock ftxp 2 6 125 KHz 7 CR80 250 1 Initialize the LED blinking base time E TCE80 1 Start the timer operation V SPT TE SAMCO S ur i LL P EEE Set the interrupt Am DD MR TM RENNES ERR REN IRE po So RE EORR ER INTMO 0500000000 Set the valid edge of INTP1 to falling edge IFO 0x00 Clear invalid interrupt requests in advance PMK1 0 Unmask INTP1 interrupts TMMK80 0 Unmask INTTM80 interrupts return KKK KK KK KKK AKA KA KA KA X AX Kk KA KK KK Kk KA Kk KK AX Kk KK KK KK kA KK KKK kck kck KK KK KK ck ko ko Main loop KK IK KK KK KK kA KK KK AX kck kA KK AX kck kA KA KK kck kck I KK KK KK I KK KK kck ck k IK KK kk KK kk void main void BI Enable vector interrupt while 1 NOP 7 NOP KKK KK KKK K
3. Stop the timer operation gt CR80 g ucCR80data g ucSWcnt Change the LED blinking base time in accordance tn subintumsoQ Service the INTTM80 interrupt PoE HI Starting interrupt servicing by INTTM80 interrupt generation Application Note U18864EJ2VOAN 15 CHAPTER 4 SETTING METHODS 4 2 Setting the LED Blinking Cycle and Chattering Detection Time The LED blinking cycle and chattering detection time are set as follows in this sample program 1 Setting the LED blinking cycle The LED output is reversed every 250 generations of 8 bit timer 80 interrupts INTTM80 in this sample program e Interrupt cycle interval time N 1 fcNr e LED output reversal cycle Interrupt cycle x Number of interrupts e LED blinking cycle 2 LED output reversal cycle x 2 Remark N CH80register setting value fent Count clock frequency of 8 bit timer 80 Calculation example The following values result when the CR80 register setting value is 249 during operation at font 125 kHz e Interrupt cycle interval time N 1 fcur 249 1 125 kHz 2 ms e LED output reversal cycle Interrupt cycle x Number of interrupts 2 ms x 250 500 ms e LED blinking cycle LED output reversal cycle x 2 500 msx2 1s Furthermore the CR80 register setting value is changed in accordance with the number of switch inputs and the LED blinking cycle is changed Number of Switch Inputs CR80 Register Setting Value In
4. Lnterrupt void in 1neems on 4 fn subinttmeot Pt Service the INTITMS0 nterrupt 7 return po RN TRETEN EE Subroutine for measuring the number of INTTM80 interrupts RECEPERAT So ek OC ET TEE EN Te AE EAE E RODEN Ce PEE SE ER eC ACCESO Se UE POOR 0 vorcd n subanttms 01 4 if g ucTM80cnt 250 Processing when the number of INTTM80 interrupts ds 50 57 g ucTM80cnt 0 Clear the number of INTTM80 interrupts P2 0bD000000015 J Reverse the LED output 47 return Application Note U18864EJ2VOAN 37 APPENDIX A PROGRAM LIST op asm Common to assembly language and C language versions OPE ET CSEG AT 0080H DB LOOTIIOO0B Option byte area BENE ME eee ar aes Low speed internal oscillator can be stopped by software ee AE High speed internal oscillation clock 8 MHz is selected for system clock source ea P34 RESET pin is used as RESET pin DB bb Protect byte area for the self programming mode E MUE TE EON H ape Sa o o All blocks can be written or erased end 38 Application Note U18864EJ2VOAN APPENDIX B REVISION HISTORY The mark lt R gt shows major revised points The revised points can be easily searched by copying an lt R gt in the PDF file and specifying it in the Find what field 2nd edition September 2008 pp 20 to 22 Modification of 5 1 Building the Sample Program p 22 5 2 Operation with SM e Addition of 1 p 26 CHAPTER 6 RELATED DOCUMENTS e Additio
5. and setting of interrupts are performed The LEDs are blinked at fixed cycles by using the generation of an 8 bit timer 80 interrupt INTTM80 after completion of the initial settings An INTP1 interrupt is serviced when the falling edge of the INTP1 pin which is generated by switch input is detected Chattering is identified when INTP1 is at high level switch is off after 10 ms have elapsed since a fall of the INTP1 pin was detected The blinking cycle of the LEDs is changed in accordance with the number of switch inputs when INTP1 is at low level switch is on after 10 ms have elapsed since an edge was detected Application Note U18864EJ2VOAN T CHAPTER 3 SOFTWARE The details are described in the status transition diagram shown below Initial settings 1 e Referencing the option byte e Selecting the high speed internal oscillator as the system clock source e The low speed internal oscillator can be stopped by software e Using the P34 RESET pin as the RESET pin e Stack pointer setting e Stopping watchdog timer operation e Setting the CPU clock frequency to 2 MHz Reset other than by LVI Reset source check LVI reset Initial settings 2 200 us wait e Setting the CPU clock frequency to 8 MHz e O port setting Voo 2 Vivi e Setting only P43 INTP1 as an input port and using an internal pull up resistor e Setting P20 as an output port and setting the output latch to high level LED off e Initi
6. TCE80 Change the LED blinking base time e Start the timer operation e Starting timer operation INTERRUPT TM80 CALL SUB INTERRUPT TM80 Service the INTTM80 interrupt RETI Return from interrupt servicing Starting interrupt servicing by INTTM80 interrupt generation 14 Application Note U18864EJ2VOAN CHAPTER 4 SETTING METHODS e C language program example same contents as in Example 1 mentioned above and the sample program void hdwinit void 4 unsigned char uccubz00us 4 S bxE variable for 200 us wert lt Setting the count clock of 8 bit timer 80 Setting the interval time i e d TMC80 0500000000 Count clock fxp 2 6 125 kHz CR80 250 1 Initialize the LED blinking base time Clearing the TCE80 1 Start the timer operation INTTM80 operation interrupt request INTMO 0500000000 5 Seb the valid edge of INIPL te falling edge flag IFO 0x00 Clear invalid interrupt requests in advance PMK1 0 Unmask INTP1 interrupts TMMK80 0 Unmask INTTM80 interrupts Enabling INTTM80 interrupt servicing void m n void ED Enable vector interrupt while 1 1 NOP NOP Setting the CR80 register after stopping timer operation with the number of switch inputs TCE80 1 Start the timer operation Starting timer pom operation s interrupt void fn_inttm80 TCE80 0
7. the Using Fixed Area of Standard Library check box is unchecked however the standard libraries such as the getchar function and malloc function will be disabled for use The Using Fixed Area of Standard Library check box is unchecked by default when the file that has been m icon is used in this sample program downloaded by clicking the LES As 20 Application Note U18864EJ2VOAN CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM 1 Start PM 2 Select tm80 prw by clicking Open Workspace from the File menu and click Open A workspace into which the source file will be automatically read will be created 3 Select Project Settings from the Project menu When the Project Settings window opens select the name of the device to be used the device with the largest ROM or RAM size will be selected by default and click OK Remark Screenshots of the Sample Program Initial Settings LED Lighting Switch Control are shown below Open Workspace Mew Ctrl Look in U18752E_78KOSKB1P_ASM_PRJ_O704_V1 v e E c EZ Open Corl inti pew Close Mew Workspace Open Workspace Click m Tlos ierksnace File name initial prv Files of type Workspace File pre v Cancel Help co nay PM initial prw OutPut File Edit Find Layer View Mayer Build Tool Window Help 3 E ci amp Select Active Project a gt Project Settings Add New Project Proje
8. LV IMD 1 Set so that an internal reset signal is generated when VDD lt VLVI j Z Seb phe Glock 32 5 PPCC 0500000000 The Clock Supplied to Lhe peripheral hardware fxp fx 8 MHz The clock supplied to the CPU fcpu 7 du o Initialize the port 0 r O e ce Rd MC MR UE NECEM RR ee m PO 0500000000 Set output latches of P00 P03 as low PMO 0511110000 Set P00 P03 as output mode D C H M Initialize the port 2 TU TEES ets ae gee ee E P MI EPEE B zr a s hh gee o O eh P2 050000000137 Set output latches of P21 P23 as low P20 as high t r ofr LED 7 PM2 0511110000 Set P20 P23 as output mode y o M CP Initialize the port 3 ec E x P3 0b00000000 Set output Latches of P305P33 as low PM3 0511110000 Set P30 P35 as output mode a E EE E Initialize the port 4 DE ED ERN EL ME E EEE EE E x P4 05000000000 Set output latches of P40 P47 as low PUA 0500001000 ZX Connect oncchrp pull up resistor to FAS 2 Application Note U18864EJ2VOAN 35 APPENDIX A PROGRAM LIST PM4 0b00001000 Set P40 P42 and P44 P47 as output mode P43 as input mode
9. PM running after completing building a project a When starting SM in PM 1 Select Register Ex tool from the Tool menu and register SM for 78KOS Kx1 2 Select Ex tool Bar from the View menu and add the SM icon to the PM toolbar 3 Click the SM icon and start SM See the PM help for details on how to register external tools b When not starting SM in PM eStart SM from the Windows start menu 22 Application Note U18864EJ2VOAN CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM 2 The following screen will be displayed when SM is started This is a sample screenshot of when an assembly language source file downloaded by clicking the icon was used e SM for 78KOS tm80 prj Seles File Edit View Option Run Event Browse Jump Simulator Window Help 1 fam ns lems E B m B Jaw uc LILI IATE EEN mc Ne E Source main asm WDTM 61116111B Set the clock 41 MOU PCC Eee The clock supplied MOU LSRCM 66660661B Stop the oscillati Check the reset source A RESF Read the reset sou BT a u SET CLOCK Omit subsequent LU Set low voltage detection MOU LUIS 66660606B Set the low voltage SET1 LUION Enable the low vol main asm 131 INS 3 Click Restart button The program will be executed after the CPU is reset and the following screen will be displayed E SM for 8KOS tm80 prj File Edit view Option Run Event B
10. describes a circuit diagram and the peripheral hardware to be used in this sample program 2 1 Circuit Diagram A circuit diagram is shown below RESET Vss 78K0S Kx1 microcontroller INTP1 P43 Note Use this in a voltage range of 4 5 V lt Vpp lt 5 5 V Cautions 1 Connect the AVner pin directly to Vpp 2 Connect the AVss pin directly to GND only for the 78K0S KB1 microcontroller 3 Leave all unused pins open unconnected except for the pins shown in the circuit diagram and the AVner and AVss pins 2 2 Peripheral Hardware The peripheral hardware to be used is shown below 1 Switch SW A switch is used as an input to control the lighting of an LED 2 LED An LED is used as an output corresponding to the interval timer function of 8 bit timer 80 and switch inputs Application Note U18864EJ2VOAN 5 CHAPTER 3 SOFTWARE This chapter describes the file configuration of the compressed file to be downloaded internal peripheral functions of the microcontroller to be used and initial settings and operation overview of the sample program and shows a flow chart 3 1 File Configuration The following table shows the file configuration of the compressed file to be downloaded main asm Source file for hardware initialization processing and main Assembly language processing of microcontroller version Assembler source file for setting the option byte sets the system clock source tm80 tmB0pw Work space fi
11. 1 ms 8 ws x 125 About 0 5 ms 8 us x 63 About 0 25 ms 8 us x 32 The interval cycle from the zeroth switch input is repeated after the fourth switch input Starting 8 bit timer 80 operation Initializing the number of INTTM80 interrupts Application Note U18864EJ2VOAN CHAPTER 3 SOFTWARE 3 4 Flow Charts The flow charts for the sample program are shown below Initial settings Note Processing after reset release Vector interrupt INTP1 gt lt Vector interrupt INTTM80 gt Reset start Vector interrupt INTP1 start Vector interrupt INTTM80 start Referencing the option byte Stack pointer settin INTTM80 interrupt P Saving the AX register data servicing Stopping watchdog timer operation Return Is an INTTM80 interrupt generated Setting the CPU clock frequency to 2 MHz Clearing INTTM80 interrupt requests f LVI reset lt INTTM80 interrupt servicing function Reset source INTTM80 interrupt servicing start INTTM80 interrupt servicing Reset other than by LVI Number of INTTM80 Have at least 10 ms interrupts elapsed Vivi 4 3 V 0 2 V 200 us wait Number of interrupts 250 Number of interrupts 250 Initializing the number of INTTM80 interrupts Reversing the LED output Clearing INTP1 interrupt requests l o Yes High level INTP1 pin level Setting so that an internal reset signal is generated when Voo Viv Low level Stop
12. 2 ms 10 ms i mseTosi2ms lt 12 ms kn m LM Suerte sea icine Linien a om YO TY EA eee nh Application Note U18864EJ2VOAN CHAPTER 4 SETTING METHODS Figure 4 4 Timing Chart Example of Chattering Detection When the LEDs Blink at Cycles of About 1 s During Switch Input About 8 us Count clock ase TL ELT LU LIU UU LH JUUL A Clear Clear Clear a TCE80 Interval time About 2 ms About 8 us x 250 INTTM80 y l Loo er E Number of interrupts after INTP1 Number of interrupts after INTP1 Number of interrupts after edge detection 1 edge detection 2 INTP1 edge detection 6 Decrement Variable for counting the number of INTTM80 6 5 4 mm 0 interrupts after INTP1 edge detection Chattering detection time About 2 ms x 5 Time until the first INTTM80 is generated after INTP1 edge detection 2 ms or less gt 10 ms INTP1 input E a b OO a Time until the first INTTM80 is generated after INTP1 edge detection 2 ms or less b About 2 ms x 5 Check the status of the INTP1 pin e INTP1 High level Identified as chattering e INTP1 Low level Identified that the switch is on Remark The variable for counting the number of INTTM80 interrupts after INTP1 edge detection depends on the LED blinking cycle during switch input The variable is 11 21 and 41 when the LEDs blink at respective cycles of about 1 2 s 1 4 s and 1 8 s Applic
13. 6 ms Blinks at cycles of about 1 4 s c T 5306 080000 T 126 000000 ji x msec Pin Name Mame LED P20 cick wice gt mes F The reversal cycle of the LED P20 is 64 ms Blinks at cycles of about 1 8 s T 803 408000 KE n 4 000000 2 msec Pin Name Name Click three times gt BH m I al P43 Notes 1 The blinking cycle from the zeroth SW button input is repeated after the fourth SW button input 2 This may differ from the actual blinking cycle depending on the operation environment of the PC borsessouteas used 24 Application Note U18864EJ2VOAN CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM Supplement The SW button hold time can be set to less than 10 ms to check whether chattering is being detected 1 Select on the toolbar 2 Right click the SW button in the I O panel window and select Properties 3 Enter 9 for the Hold Time and click the OK button tmB00 pni EIE Parts Button Properties Button L onnectian Style Label Sw Pin Mame P43 TXO6AINTP1 lt Active Level LOW C HIGH Properties Type f Push Toggle Group Group Mame Hold Time Enter 9 then click the OK button Cancel Appl Help lt 4 gt Select on the toolbar 5b Execute the program and click the SW button Even if the SW button is clicked chattering will be identified and the LE
14. Application Note 78KO0S Kx1 NIEC Sample Program 8 bit Timer 80 Interval Timer This document describes an operation overview of the sample program and how to use it as well as how to set and use the interval timer function of 8 bit timer 80 In the sample program the LEDs are blinked at fixed cycles by using the interval timer function of 8 bit timer 80 Furthermore the blinking cycle of the LEDs is changed in accordance with the number of switch inputs Target devices 78KOS KA1 microcontroller 78KOS KB1 microcontroller Document No U18864EJ2VOANO0 2nd edition Date Published September 2008 NS NEC Electronics Corporation 2007 Printed in Japan CONTENTS CHAPTER T OVERVIEW eei eacus sea uan EP Eee co eas e ha eine UH t cesses Suse ioraa 3 1 14 Main Contents of the Initial Settings seessseeeeeeeeeeeneee 3 1 2 Contents Following the Main LOOp 22 2 ee eee en 4 CHAPTER 2 CIRCUIT DIAGBAM ccce oe ooo nn Baa Ka xa He ke a Ano KES KRK En SKa 5 Ze Cruit BIRD 5 2 2 Peripheral Hardware eneensnnnnnnesnnnsesrnrrrrtrrrrrresrrrosrrrrsnrnrrnnnrernnrerennnene 5 CHAPTER 3 SOFTWARE 1i einen rk so ke nu eR CUR cano eap uenea aa iaioa SU SAUNA SUK SR EA Ie Rea CUM USES 6 Sn NEN LIEGT 6 3 2 Internal Peripheral Functions to Be Used ee 7 3 3 Initial Settings and Operation Overview eee 7 94 deo Gas dorii oat vec E I o ENA 9 CHAPTER 4 SETTING METHODS
15. C KC Ck K KC AA Kk KC KC A k Kok 4 4 Ko KC KC A Kk KK A Kk 4 4 4 A KK A A4 4 4 4 A 4 4 4 4 4 4 4 4 4 47 4 4 A2 7 4 KU 4 4 7 47 2 KD KG 4 4 KC Kk 4 Kok kk Interrupt INTTM80 r ZX AAA AA KC KC Ck Ko KC AA Kk KC KC A ok Kok Kok Ko 4 kk Kk 4 Kk A 4 Ko KC Kok KK KC Kk 4 4 KC A 4 KK KK 4 4 4 4 47 4 4 A4 47 4 4 4 4 47 4 KG 4 4 KG KG A 4 42 KK Kk kk INTERRUPT_TM80 CALL SUB INTERRUPT TM80 Service the INTTM80 interrupt RETI Return from interrupt servicing OA E Subroutine for measuring the number of INTTM80 interrupts SUB INTERRUPT TM80 DBNZ CNT_TM80 SEND INTTM80 Branch if the number of INTTM80 interrupts lt 250 MOV CNT_TM80 250 I Initialize the number ot INITIM20 interrupts XOR Es 00000001B Reverse the LED output END INTTM80 RET gt Return from the Subroutine end 32 Application Note U18864EJ2VOAN APPENDIX A PROGRAM LIST main c C language version KKK KK KK KK KK KA KA KA Kk kA kA KK AX Kk kA Kk KK KK Kk kA kA KA X AX kA kA kA kA kck kck ck kk kk kck ck k ko NEC Electronics 78K0S KB1 OKCk Kok Ck ok KO KC KC Ck Kk KC AA HA A KC Kok Ko Kk A A Kk KC KC 4 4 KK A4 Kk KK KK KK KK 4 4 4 A4 4 4 4 4 A4 4 KK 4 4 4 A4 47 4 KU KG 4 4 KG KG A X Z A A 4 Kok A A A 78K0S KB1 Sample program OKCk Kok CK Ck KC KC KC ok Z AA k Kok Kok Ko Kk A A Ko 4 4 A 4 KK KK KK KK KK A A 4 4 4 A 4 4 4 4 4 4 4 4 KK 4 KU KU 47 4 KU KG 4 KG KG KG KG 4 KC KC A 4 Kok kA Sepp Eimer 60 ck ok ck ok ko
16. D blinking cycle will not change because the button hold time is 9 ms Application Note U18864EJ2VOAN 25 CHAPTER 6 RELATED DOCUMENTS aose ee EE EEE MS E RA78K0S Assembler Package User s Manual Language Operation C CC78K0S C Compiler User s Manual Language mE Operation T oe lt R gt Flash Programming Manual Basic MINICUBE2 version 78KOS Kx1 Sample Program Startup Guide Application Note Sample Program Initial Settings LED Lighting Switch Control Sample Program Interrupt External Interrupt Generated by Switch Input PDF Sample Program Low Voltage Detection Reset Generation During PDF Detection at Less than 2 7 V 26 Application Note U18864EJ2VOAN APPENDIX A PROGRAM LIST As a program list example the 78KOS KB1 microcontroller source program is shown below main asm Assembly language version 0900990999090 9999990390999 3999999997970 NEC Electronics 78K0S KB1 E o ue eque CQ I Ua ce dU ed e UV UD GG RR DR IUIS UNO GO CONUAT UD ING URGE Ri ICON OK gern ONUS US j 78KOS KB1 Sample program Ge a o o a Ie Bor Pe EE o a EN TyTN OST EEN oo I Tat o o a o OG E o TS ORS o o a k OT tes Die EE o a a a OTS Rais Oe E E bo ho a CUN B bwt tamer 90 e 80 AS ORO IS NUNC ETENE CIN VRCASUE SCIO UR E E GUN ETE E E RE E 90 SH SOE gt gt A ZOO a a E Release EERE 00 9 EER RE E E R EERE ERRE Diy EEEE E EE E EE E DTN DE Diy EER E EERI EREE ERRER Dy EEE REE IS Dep EEE R EREE E EEE N E 7 lt lt Ov
17. K kk KA KA KA X AX kA kA KK KK Kk kA KK KK AX kA kA KK KK Kk kA KK KKK ck k ck ck KK KK KK kck ko External interrupt INTP1 KK I KK KK KK KK kA KK KK AX kA KK KA KK kA KA KK kck k kc KK KK KK I KK KK kck ck k ck kck kk kk KK kk z interrupt vord GIL tm bo unsigned char ucChat I B bit Variable Tor cemoving chattering 36 Application Note U18864EJ2VOAN APPENDIX A PROGRAM LIST for ucChat g ucChat g ucSWcnt ucChat gt 0 ucChat Wait of about 10 ms for removing chattering while TMIF80 Wait for the INTTM80 interrupt request NOP j TMIF80 0 Clear the INTTM80 interrupt reguest Flag fn subasmbtumeotc F Service the INITMS0 interrupt PIF1 0 Clear the INTELI interrupt request EE EPA LS Processing performed if SW is on for 10 ms or more x g ucSWcnt g ucSWcnt 1 amp 0b00000011 Increment the number of switch inputs by 1 TCE80 0 ZP Stop tne timer Operation CR80 g_ucCR80data g_ucSWent Change the LED blinking base time in accordance with the number of switch inputs TCE80 1 Start the timer operation g ucglTMOOUQHE 959 Clear the number of INTTM80 interrupts di j peturn KK KK KKK KK KK AKA KA KA KA X AX Kk kA KK KK Kk kA KK KK AX Kk Ck KK KK AZ kA KK KKK kck kck kK KK KKK ck ko ko Interrupt INTTM80 KK KK KK KK KK AA KA KK kk kck kA kA KA KA X kck kA kA KK kck k kc kA KA KA X kck kA KK KKK ck ck ck kck kk kk KK kk
18. L P43 Outputs POO P03S P20 P22 P30 P33 B40 PA2 P42 P4T All unused ports are set as the output mode EI20 P1235 PLU CKCKC AAA KC KC KC Ck Kk KC AA Kk KC KC A ok Ko KC Kk A Ko KC Kk Kk K KC Kk A Kk 4 4 CK A KK KK 4 4 KU A4 4 4 4 4 4 4 4 42 2 4 4 4 2 47 4 4 KO KK 47 4 KG KG 4 4 K A2 4 Kok kk kk AVCI CSEG AT 0000H DW RESET START 00 RESET DW RESET START ze DW RESET START 04 DW RESET_START C06 INILVI DW RESET START oOo INTPO DW INTERRUPT RI OA INIP DW RESET_START 0C INTIMAL DW RESET_START DB INTTIMOO0 DW RESET STARI Oy CDNIXMOTO DW RESET START SPA NT AD DW RESET START 14 DW RESET START 16 INIP2 DW RESET START 18 INTP3 DW INTERRUPT TM80 LA INTTM80 DW RESET START sq 010 INTSREO DW RESET START 1E INTSRO DW RESET STARI 2020 INT SS Define the ROM data table L l l llllllclllllllllllllllllllllllllllllllllllllllllllllll lll l XROM CSEG AT 0100H Sa Por setting the timer OU cycle DB Zod L ms interval compare value DB 25 e 1 ms interval compare value DB 63 0 5 ms interval compare value DB mc 0 25 ms interval compare value For handling chattering DB el Count value for handling chattering for 2 ms interval DB LO Count value for handling chattering for 1 ms interval DB
19. LED blinking cycles SW Inputs LED Blinking P43 Cycle P20 ic pU EOS O times 1 second 1 time l 172 second 2times 1 4 second 3 times 1 8 second The blinking cycle from the zeroth switch input is repeated after the fourth switch input SEA port Servings gt Application Note U18864EJ2VOAN 33 APPENDIX A PROGRAM LIST Input P43 Qu tp ts EUUSEUSy BZ0 P23p B30 P35 P40 P42 PAAPA p PIZU EIZS Piso All unused ports are set as the output mode KCkCkCk kk kk kk kk Ck k ck kk kk kk AX kck ck kk kk kk k kc kA KA KA K kck kck kA KA KA X kck k k ck kk kk kck ck k kA kA kA kk kk P RR Preprocessing directive pragma oragma SFR SFR names can be described at the C source level oragma EI JF EI instructions can be described at the Source level X oragma NOP NOP instructions can be described at the C source level oragma interrupt INTP1 fn_intpl Interrupt Lune bon declarstriom INTEL 4 fpragma interrupt INTTM80 fn inttm80 ZX ubalerrcupb JBonetcen declaration INTTM80 eec e eee Declare the function prototype void fn subinttm80 1 INTIMSO Interrupt subroutine 55 SS Define the global variables sreg unsigned char g ucSWcnt 0 8 bit variable for counting the number Oft Switch inputs sreg unsigned char g ucTM80cnt 0 8 bit variable for co
20. OAN 1 mh 12 CHAPTER 4 SETTING METHODS Example 1 Setting the count clock of 8 bit timer 80 to fxr 2 fxP 8 MHz e Setting the interval cycle to 2 ms and starting timer operation Same content as in the sample program TMC80 reo o o o o o o o Oooo Count clock selection La e pe S Enabling of timer operation 0 Stops operation clears the counter to 0 Enables operation CR80 setting value N 249 e Count clock fent 8 MHz 2 0 125 MHz 125 kHz e Interval cycle 2 ms N 1 125 kHz N 2 ms x 125 kHz 1 249 Timer operation is started by setting 1 to TCE80 after setting 00000000 to TMC80 and 249 to CR80 e Assembly language TMC80 00000000B CR80 249 TCE 0 e C language TMC80 05000000000 CR80 249 TCE80 Application Note U18864EJ2VOAN CHAPTER 4 SETTING METHODS Example 2 e Setting the count clock of 8 bit timer 80 to fxe 2 fxP 8 MHz e Setting the interval cycle to 32 ms and starting timer operation TMC80 Count clock selection Enabling of timer operation Stops operation clears the counter to 0 Enables operation CR80 setting value N 249 e Count clock fent 8 MHz 2 0 0078125 MHz 7 8125 kHz e Interval cycle 32 ms N 1 7 8125 kHz N 32 ms x 7 8125 kHz 1 249 Timer operation is started by setting 1 to TCE80 after setting 00000100 to TMC80 and 249 to CR80 e Assem
21. ZO Count value for handling chattering for 0 5 ms interval DB 40 1 Count Value for handling chattering Ior 05 25 xus interval Application Note U18864EJ2VOAN APPENDIX A PROGRAM LIST k Define the RAM XRAM DSEG SADDR CNT TM80 BAS 1 For counting INTTM80 interrupt 7 Define the memory stack area XSIK DSEG AT OFEEOH STACKEND DS 20H Memory stack area 32 bytes SLAGKTOBY Start address of the memory stack area FFOOH eCACKCk KC KC Ck KO AAA K KC A A A KC A A k KC Kk Kok Ko Kk 4 A 4 KK A Kk KK KK KK A A 4 4 A A 4 4 4 4 4 4 4 4 4 Z KU 47 4 KU KO KK 47 4 KG KG KG KG X K 4 4 2 AA X2 lInitralrzdtrlon after RESET eOACKCkK KC KC Ck KO KC KC ok Kk KC Kk ok k KC KC A ok Kok 4 4 Ko 4 kk 4 Kok Kk 4 Ko KK Kk KK KC A4 4 4 4 A4 4 KK KU 4 4 4 4 A4 4 4 4 2 7 47 4 KU KK 4 KG KG 47 4 K KK 4 Ko Kk AA X4 XMAIN CSEG UNIT RESEI START MOVW AX STACKTOP MOVW SP AX set the stack pointer MOV WDTM 01110111B Stop the watchdog timer operation Detect low voltage set the clock SEE oer the clock Lo eme MOV PCC 00000000B 2 Ihe clock supplied to the CPU Cfopu Exp fx 4 2 MHz MOV LSRCM 00000001B Stop the oscillation of the low speed internal oscillator IESU e Check the reset source eee MOV Ay RESF Read the reset s
22. alizing the number of INTTM80 interrupts e 8 bit timer 80 setting e Setting the count clock to fxe 29 125 kHz e Setting the interval cycle to 2 ms 8 us x 250 e Starting timer operation e nterrupt setting e Setting the valid edge of INTP1 external interrupt to the falling edge e Enabling INTP1 and INTTM80 interrupts Setting Vivi to 4 3 V 0 2 V and starting low voltage detection operation Setting so that an internal reset signal is generated when Vpop lt Vivi INTTM80 interrupt generation ounting the number of INTTM80 interrupt generations Waiting for interrupt generation Number of INTTM80 interrupts lt 250 EN Seve INTE aling Number of INTTM80 interrupts chattering edge detection 250 detection Initializing the number of INTTM80 interrupts Reversing the LED output Waiting for INTTM80 interrupt generation Elapsed time Clearing INTTM80 since edge interrupt requests detection lt INTTM80 interrupt generation ounting the number o about 10 ms INTTMB8O interrupt Number of INTTM80 interrupts lt 250 sam Number of INTTM80 interrupts Checking the wait time 250 Elapsed time since edge detection gt Initializing the number of about 10 ms INTTM80 interrupts Clearing INTP1 interrupt requests Reversing the LED output INTP1 Low level Stopping 8 bit timer 80 operation Changing the interval cycle No of SW inputs Interval cycle About 2 ms 8 ws x 250 About
23. ation Note U18864EJ2VOAN 19 HR CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM This chapter describes how the sample program operates with system simulator SM for 78KOS Kx1 by using the 5 1 Building the Sample Program To check the operation of the sample program by using system simulator SM for 78KOS Kx1 hereinafter referred to as SM SM must be started after building the sample program This section describes how to build a sample program by using the assembly language sample program source program project file downloaded by clicking the BEEN icon See the 78K0S Kx1 Sample Program Startup Guide Application Note for how to build other l i downloaded programs For the details of how to operate PM refer to the PM Project Manager User s Manual r Column Build errors Change the compiler option setting according to the following procedure when the error message A006 File not found C NECTOOLS32 LIB78KOS sOsl rel or ERROR F206 Segment DATA can t allocate to memory ignored is displayed when building with PM 1 Select Compiler Options from the Tool menu 2 The Compiler Options dialog box will be displayed Select the Startup Routine tab 3 Uncheck the Using Fixed Area of Standard Library check box Leave the other check boxes as they are A RAM area of 118 bytes that has been secured as a fixed standard library area will be enabled for use when
24. bly language MOV TMC80 00000100B MOV CR80 249 SET1 TCE80 e C language TMC80 05000000100 CR80 249 TCE80 Application Note U18864EJ2VOAN 13 CHAPTER 4 SETTING METHODS e Assembly language program example same contents as in Example 1 mentioned above and the sample program XMAIN CSEG UNIT RESET START Setting the count clock of 8 bit timer 80 Setting the interval time e MOV TMC80 00000000B Count clock fxp 2 6 125 kHz MOV A HL Read from the table the base time initial values for blinking the LEDs MOV CR80 A Initialize the compare values SET1 TCE80 e Clearing the INTTM80 interrupt request Starting timer operation Start the timer operation e flag INTMO 00000000B Set the valid edge of INTP1 to falling edge MOV IFO 00H Clear invalid interrupt requests in advance CLR1 PMK1 Unmask INTP1 interrupts CLR1 TMMK8 0 Unmask INTTM80 interrupts Enabling EI INTTMBO interrupt Enable vector interrupt servicing MAIN LOOP NOP BR SMAIN LOOP Go to the MAIN LOOP CLR1 TCES80 Stop the timer operation e MOV A L Read the lower 8 bits of the table address Setting the CR80 INC A Increment the table address by 1 register after AND A 00000011B Mask bits other than bits 0 and 1 stopping timer MOV L A Write to the lower 8 bits of the table address operation MOV A HL Read the table data JA MOV CR80 A SET1
25. ct Information Source File Tool Version Settings Initialization Initialization Insert Project ProjectWindow ONSE a Project File Name initial pri H3 Initialization 1 Pr Folder D download LI18752E 78K SKB1P ASM PRJ 0704 V1 amp Initialization Source Files Include Files Project Relate Other Files Workspace File Name D download U18752E_78KOSKB1P_4SM_PRJ_0704_ 1 initial prw Project Settings Add Source Files Project Group Initialization Add Other Files Project Title Initialization Device Name uPD78F 9232 v uPD 8F9212 uPD 78F3221 Microcontrollers Name 7 K0S we Device Install Edit project settings uPD 78F3232 T This will be displayed 2405 The NEC Electronics tool to be used was changed whe n the device name When these tools are changed it is necessary to compile all source files at the time of next build is chan ged Are all object Files deleted in order to compile all source Files at the time of next build Application Note U18864EJ2VOAN 21 CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM 4 Click m Build button When the source files are built normally the message 13500 Build completed normally will be displayed b Click the OK button in the message dialog box A HEX file for flash memory writing will be created Re
26. diaries 2 NEC Electronics products means any product developed or manufactured by or for NEC Electronics as defined above M8E 02 11 1 Application Note U18864EJ2VOAN CHAPTER 1 OVERVIEW An example of using the interval timer function of 8 bit timer 80 is presented in this sample program The LEDs are blinked at fixed cycles and the blinking cycle of the LEDs is changed in accordance with the number of switch inputs Caution 8 bit timer 80 is not mounted with the 78K0S KU1 and 78KOS KY1 microcontrollers 1 1 Main Contents of the Initial Settings The main contents of the initial settings are as follows e Selecting the high speed internal oscillator as the system clock source e Stopping watchdog timer operation e Setting Vivi low voltage detection voltage to 4 3 V 0 2 V e Generating an internal reset LVI reset signal when it is detected that Vpp is less than Vivi after Voo power supply voltage becomes greater than or equal to Vivi e Setting the CPU clock frequency to 8 MHz e Setting the I O ports e Setting 8 bit timer 80 e Setting the count clock to fxP 2 125 kHz e Setting the interval cycle to 2 ms 8 us x 250 e Setting the valid edge of INTP1 external interrupt to the falling edge e Enabling INTP1 and INTTM80 interrupts Note This is set by using the option byte Application Note U18864EJ2VOAN 3 CHAPTER 1 OVERVIEW 1 2 Contents Following the Main Loop The LEDs are blinked at fixed cycles by using the
27. ernal interrupt INTP1 OKCK KC KC Ck ok K KC Ck ok Kk KC Kk Kk A Kok Kok Ko Kk A A K 4 KK Kk KK KK KK A4 A4 4 4 4 A 4 KI A4 4 4 4 4 A 4 4 4 A4 47 4 KU 42 4 47 KG 4 KG 47 4 K A2 4 4 2 Kk k Kk INTERRUPT Pl PUSH AX Save the AX register data to the stack PINE L0 ms wait bo handle chattering MOV A HL 4 Read the count value corresponding to the timer 80 cycle WAIT CHAT NOP BE TMIF80 SWAIT CHAT Wait for the INTTM80 interrupt CLRI TMIF80 Clear the INTTM80 interrupt request flag CALL I SUB INTERRUPT TM80 Service the INTTM80 interrupt DEC A Decrement the A register by 1 BNZ SWAIT CHAT Branch if not A 0 CLElI PIFI Clear the INTP1 interrupt request pese Identification of chattering detection BT P4 3 SEND INTP1 Branch if there is no switch input jew Change the TM80 interval cycle CLRI1 TCE80 Stop the timer operation Application Note U18864EJ2VOAN 31 APPENDIX A PROGRAM LIST MOV A L Read the lower 8 bits of the table address INC A increment the table address by 1 AND A 00000011B Mask bits other than bits 0 and 1 MOV I A Write to the lower 8 bits of the table address MOV A ELE Read the table data MOV CREO A Change the LED blinking base time SETI TOES Start the timer operation MOV CNT TM80 4250 Inztraolize the number oft INITMS0 anterrupts END INTEL POP AX Restore the AX register data RETI Return from interrupt servicing eOKCKC KOC KC Ck KC K
28. erview gt gt This sample program presents an example of using the interval timer function of 8 bit timer 80 The LEDs are blinked by reversing the P20 pin output through the use of 8 bit timer 80 interrupts The LED blinking cycle is changed by rewriting the compare register of the timer when a switch input interrupt is generated Principal setting contents gt Stop the watchdog timer operation Set the low voltage detection voltage VLVI to 4 3 V 0 2 V Generate an internal reset signal low voltage detector when VDD VLVI after VDD gt VLVI fo SSL thee PU clock do 9 MHZ Set the clock supplied to the peripheral hardware to 8 MHz Set the valid edge of external interrupt INTP1 to falling edge Set the chattering detection time during switch input to 10 ms lt 8 bit timer 80 settings D Count Glock ixp72 6 125 kHz Initial value of timer cycle 2 ms 8 us clk x 250 count 2 ms Number of switch inputs and LED blinking cycles eS SSS SS SW Inputs LED Blinking P43 Cycle P20 j 5 0 times Ll second 1 time theo useconmcd 2times 1 4 second 3 times 1 8 second peperere sesion aderire ess Application Note U18864EJ2VOAN 27 APPENDIX A PROGRAM LIST The blinking cycle from the zeroth switch input is repeated after the fourth Switch input S21 O port Settings J3Unpub
29. generation of an 8 bit timer 80 interrupt INTTM80 after completion of the initial settings An INTP1 interrupt is serviced when the falling edge of the INTP1 pin which is generated by switch input is detected Chattering is identified when INTP1 is at high level switch is off after 10 ms have elapsed since a fall of the INTP1 pin was detected The blinking cycle of the LEDs is changed in accordance with the number of switch inputs when INTP1 is at low level switch is on after 10 ms have elapsed since an edge was detected Number of switch inputs O Output Blinks at cycles of about 1 s Number of switch inputs 3 27 Number of switch inputs 1 Switch inputNote Switch input C Output Blinks at cycles of about 1 2 s Output Blinks at cycles of about 1 8 s gt Switch input C Number of switch inputs 2 P di Switch input v lt Output gt Blinks at cycles of about 1 4 s Note The blinking cycle from the zeroth switch input is repeated after the fourth switch input Caution For cautions when using the device refer to the user s manual of each product 78K0S KA1 78K0S KB1 NE Column Chattering Chattering is a phenomenon in which the electric signal repeats turning on and off due to a mechanical flip flop of the contacts immediately after the switch has been pressed 4 Application Note U18864EJ2VOAN CHAPTER 2 CIRCUIT DIAGRAM This chapter
30. kck XZ A A X KK 4 4 Z KKK KK Z A Z A Z KK Z Z KKK KKK KK Z Z ko ok ck kok Z kokok kok ck kok kockok kockok kok k KKK KKH lt lt History gt gt ZOOM Lass Release OKCk KK CK Ck KC KC KC Ck K KC KC Kk Kk K A A Ko Kk A Kk 4 KC 4 CK 4 4 4 A4 4 KK X4 A 4 74 A A 4 4 4 A 4 4 4 4 A4 4 KU A4 47 4 KU 4 47 4 4 4 47 4 KG KU 4 4 KC KC A 4 Kok kk lt lt Overview gt gt This sample program presents an example of using the interval timer function of 8 bit timer 80 The LEDs are blinked by reversing the P20 pin output through the use of 8 bit timer 80 interrupts The LED blinking cycle is changed by rewriting the compare register of the timer when a switch input interrupt is generated lt Principal settling contents Declare a functron cun by arn interrupt INLPL In I nmntplc Declare a function run by an interrupt INTTM80 gt fn inttm80 Stop the watchdog timer operation Set the low voltage detection voltage VLVI to 4 3 V 0 2 V Generate an internal reset signal low voltage detector when VDD VLVI after VDD gt VLVI Set the CPU clock to 8 MHz Set the clock supplied to the peripheral hardware to 8 MHz Set the valid edge of external interrupt INTP1 to falling edge Set the chattering detection time during switch input to 10 ms 8 bit timer 80 settings Count Glock fxp72 6 125 kHz Initial value of timer cycle 2 ms 8 us clk x 250 count 2 ms Number of switch inputs and
31. le for integrated development environment PM o tm80 prj Project file for integrated development environment PM o foo tm80 pri Project files for system simulator SM for 78KOS Kx1 tm80 prs tm80 prm tm800 pnl I O panel file for system simulator SM for 78K0S Kx1 used for checking peripheral hardware operations tm800 wvo Timing chart file for system simulator SM for 78KOS Kx1 used for checking waveforms Note main asm is included with the assembly language version and main c with the C language version Remark Only the source file is included The files to be used with integrated development environment PM and 78K0S Kx1 system simulator SM are included The microcontroller operation simulation file to be used with system simulator SM for 78K0S Kx1 is included 6 Application Note U18864EJ2VOAN CHAPTER 3 SOFTWARE 3 2 Internal Peripheral Functions to Be Used The following internal peripheral functions of the microcontroller are used in this sample program e Interval timer function 8 bit timer 80 e Vpp lt Vivi detection Low voltage detector LVI e Switch input INTP1 P43 external interrupt e LED output P20 output port 3 3 Initial Settings and Operation Overview In this sample program initial settings including the setting of the low voltage detection function selection of the clock frequency setting of the I O ports setting of 8 bit timer 80 interval timer
32. mark Screenshots of the Sample Program Initial Settings LED Lighting Switch Control are shown below cc z PM initial prw OutPut File Edit Find Layer View Project Build Tool Window Help Dae 6 Sal Initialization Initialization M Debug Build v ProjectWindow Files Memo BX output Initialization 1 Project s Initialization J Source Files Include Files s G Project Related Files OutPut EEr 23 Other Files C Program Files NEC Electronics ToolsYRA7S8KO0S W2 003binVra78k0s exe fmain prat PASS OUTOBJ Startt Assembly complete O error s and 0 warning s found C Program Files NEC Electronics Toolsi RA78SKOS U2 00 bin ra78k0s exe fop prat PASS OUTOBJ Start Assembly complete c Program Files NE PskO0s exe fmain plki Link complete C Program Files NE PS8k0s exe fa poct Object Conversion Co yis found Build Total error s A HEX file for flash memory writing will be generated 5 2 Operation with SM This section describes examples of checking the operation on the I O panel window or timing chart window of SM For the details of how to operate SM refer to the SM System Simulator Operation User s Manual HR 1 When SM for 78KOS Kx1 W1 02 SM hereafter is used in the environment of PM Ver 6 30 SM cannot be selected as the debugger In this case start SM via method a or b described below while keeping
33. n of Flash Programming Manual Basic MINICUBE2 version Application Note U18864EJ2VOAN 39 For further information please contact NEC Electronics Corporation 1753 Shimonumabe Nakahara ku Kawasaki Kanagawa 211 8668 Japan Tel 044 435 5111 http www necel com America NEC Electronics America Inc 2880 Scott Blvd Santa Clara CA 95050 2554 U S A Tel 408 588 6000 800 366 9782 http www am necel com Europe NEC Electronics Europe GmbH Arcadiastrasse 10 40472 Dusseldorf Germany Tel 0211 65030 http www eu necel com Hanover Office Podbielskistrasse 166 B 30177 Hannover Tel 0 511 33 40 2 0 Munich Office Werner Eckert Strasse 9 81829 M nchen Tel 0 89 92 10 03 0 Stuttgart Office Industriestrasse 3 70565 Stuttgart Tel 0 711 99 01 0 0 United Kingdom Branch Cygnus House Sunrise Parkway Linford Wood Milton Keynes MK14 6NP U K Tel 01908 691 133 Succursale Francaise 9 rue Paul Dautier B P 52 78142 Velizy Villacoublay C dex France Tel 01 3067 5800 Sucursal en Espana Juan Esplandiu 15 28007 Madrid Spain Tel 091 504 2787 Tyskland Filial Taby Centrum Entrance S 7th floor 18322 Taby Sweden Tel 08 638 72 00 Filiale Italiana Via Fabio Filzi 25 A 20124 Milano Italy Tel 02 667541 Branch The Netherlands Steijgerweg 6 5616 HS Eindhoven The Netherlands Tel 040 265 40 10 Asia amp Oceania NEC Electronics China Co Ltd 7th Floor Q
34. ource BT A 0 SSET CLOCK Omit subsequent LVI related processing and go to SET CLOCK during LVI reset Set low voltage detection MOV LVIS 00000000B Set the low voltage detection level VLVI to dod WV 0 Ww Sati JVION Enable the low voltage detector operation MOV A 40 Assign the 200 us wait count value jc 20 0 IB MA 56 WAIT 2000U0S DEC A Application Note U18864EJ2VOAN 29 APPENDIX A PROGRAM LIST BNZ SWAIT 200US x O 5Imge ccE s Olcik x 00500utt l 20008 a SS VDD gt VLVI wait processing WAIT _ LVI NOP BI LVIF SWAIT_LVI Branch t VDD lt ViVi SET1 LVIMD Set so that an internal reset signal is generated when VDD VLVI Saas Set the clock 2 SET CLOCK MOV PPCC 00000000B The clock supplied to the peripheral hardware fxp fx 8 MHz gt The clock supplied to the CPU fcpu fxp MOV PO 00000000B Set output latches of POO P03 as low MOV PMO 11110000B Set P00 P03 as output mode MOV P2 00000001IB Set Output batenes ot B21 P23 as low P20 as high turn off LED MOV PMO SELILIIOO00B 4 Set B20P23 a Output mode MOV P3 00000000B Set output latches of P30 P33 as low MOV PM3 4IILIT0000B Set P30 5P33 as output mode MOV PA 00000000B Set output latches of P40 P47 as low MOV PU 00001L000B Connect on ohip pull up resistor to P43 MOV PMA 00001000B Set P40 P42 and P44 P47 as output mode P43 as MOV P12 00000000B Set
35. output latches of P120 P123 as low MOV PMIZ s3ELIITO00UB Set Pl20 Pl23 as output mode MOV Pl3 d300000001B Set output latch of PI30 as high MOV CNT_TM80 250 s tno tie line the number or INIIMO0 interrupts 30 Application Note U18864EJ2VOAN APPENDIX A PROGRAM LIST MOVW HL 0100H Specify the table address to HL used for INTP1 interrupt MOV TMC80 00000000B Count clock fxp 2 6 125 kHz MOV A HL Read from the table the base time initial values for blinking the LEDs MOV CR80 A Initialize the compare values SETI TCESO Start the timer operation Set the interrupt MOV INTMO 100000000B Set the valid edge of INIL to falling edge MOV LEO DOR Clear invalid interrupt requests in advance CLERI BMR Unmask INTP1 interrupts CLRI1 TMMKS80 Unmask INTTM80 interrupts EI Enable vector interrupt eOACKCk KC KC Ck KO AAA Kk KC AA Kk KC KC A ok Kok Kk A Ko Kk kk 4 KK A4 Kk 4 4 A4 A KK A A4 4 4 K A 4 KK KU 4 4 4 4 4 4 4 KU A2 47 4 4 X 4 47 2 2 KG 4 4 KG A 4 42 A A A kk Main loop eOACKCk KC KC Ck KO AAA KC AA Kk KC KKK Kok 4 A Ko Kk 4 Kk K KK A Kk KK A4 A KK A A 4 4 A A4 4 4 4 4 4 4 4 4 4 474 4 A2 427 4 4 KU 4 7 47 42 KG KG 4 4 A A 4 K Kk kA kk MAIN LOOP NOP BR SMAIN LOOP Go to the MAIN LOOP eOACKCkK KC KC Ck KC AAA Kk KC Kk ok k KC KC A A Kok Kk A Ko Kk kk 4 Ko Kk A4 4 Ko KC Kk Kk KK KC A 4 4 CK A 4 KK 4 4 4 4 4 4 47 4 4 A4 7 4 4 KK 4 4 42 KG 4 KG KR A 4 4 Kk A AX Ext
36. ping 8 bit timer Setting the CPU clock 80 operation frequency to 8 MHz Reading the interval cycle I O port setting corresponding to the number of SW inputs Initializing the number of INTTM80 interrupts Changing the interval cycle 8 bit timer 80 setting e Setting the count clock to fxp 2 125 kHz Starting 8 bit timer 80 operation e Setting the interval cycle to 2 ms 8 us x 250 Starting 8 bit timer i Initializing the number of 80 operation INTTM80 interrupts INTP1 setting Restoring the AX register data Enabling interrupt Return Infinite loop Referencing the option byte is automatically performed by the microcontroller after reset release In this sample program the following contents are set by referencing the option byte e Using the high speed internal oscillation clock 8 MHz TYP as the system clock source e The low speed internal oscillator can be stopped by using software e Using the P34 RESET pin as the RESET pin Application Note U18864EJ2VOAN 9 CHAPTER 4 SETTING METHODS This chapter describes the interval timer function of 8 bit timer 80 For other initial settings refer to the 78KOS Kx1 Sample Program Initial Settings LED Lighting Switch Control Application Note For interrupt refer to the 78KOS Kx1 Sample Program Interrupt External Interrupt Generated by Switch Input Application Note For low Mid detection LVI refer to the 78KOS Kx1 Sample For how to set registe
37. ronics products developed based on a customer designated quality assurance program for a specific application The recommended applications of an NEC Electronics product depend on its quality grade as indicated below Customers must check the quality grade of each NEC Electronics product before using it in a particular application Standard Computers office equipment communications equipment test and measurement equipment audio and visual equipment home electronic appliances machine tools personal electronic equipment and industrial robots Special Transportation equipment automobiles trains ships etc traffic control systems anti disaster systems anti crime systems safety equipment and medical equipment not specifically designed for life support Specific Aircraft aerospace equipment submersible repeaters nuclear reactor control systems life support systems and medical equipment for life support etc The quality grade of NEC Electronics products is Standard unless otherwise expressly specified in NEC Electronics data sheets or data books etc If customers wish to use NEC Electronics products in applications not intended by NEC Electronics they must contact an NEC Electronics sales representative in advance to determine NEC Electronics willingness to support a given application Note 1 NEC Electronics as used in this statement means NEC Electronics Corporation and also includes its majority owned subsi
38. rowse Jump Simulator Window Help py ru s Be me Qh zm mv Click lt BA SE T 2 m 2 e BB zt sale i5 SI O08 OA BLAS Source main asm DBR tm800 pnl LED blinks Pec eaaaaa00R s the Glock supplied repeatedly at fixed LSRCM HOODBORO B Stop the oscillati cycles Check the reset source MOU A RESF Read the reset sou BT A B SET_CLOCK Omit subsequent LU Set lou voltage onn MOU LUIS 66660606B Set the louvu voltag SET1 LUION Enable the low vol 2 x menasm i3l eR o 00 AUTO INS This turns red during program execution Application Note U18864EJ2VOAN 23 CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM 4 Click the SW button in the I O panel window during program execution Check that the blinking cycle of LED in the I O panel window and the waveforms in the timing chart window change depending on the number of SW button inputs I O panel window Timing chart window Blinks at cycles of The reversal cycle of the LED P20 is 500 ms about 1 s m i J 0 064000 500 064000 WF E 500 000000 E msec Pin Name Name Do not click m S as SW P43 The reversal cycle of the LED P20 is 250 ms Blinks at cycles of about 1 2 s T 2116 080000 ES caoooo FY P50 000000 2 msec Pin Name Mame LED F20 Cone gt NN mes E E Note 1 The reversal cycle of the LED P20 is 12
39. rs refer to the user s manual of each product 78KOS KA1 78K0S KB1 For assembler instructions refer to the 78K 0S Series Instructions User s Manual 4 1 Setting the Interval Timer Function of 8 bit Timer 80 The following two types of registers are set when using 8 bit timer 80 e 8 bit timer mode control register 80 TMC80 e 8 bit compare register 80 CR80 1 Setting regarding the operation mode of 8 bit timer 80 The count clock of 8 bit timer 80 is selected and operation is controlled by using 8 bit timer mode control register 80 TMC80 10 Application Note U18864EJ2VOAN CHAPTER 4 SETTING METHODS Figure 4 1 Format of 8 bit Timer Mode Control Register 80 TMC80 TMC80 E uc Count clock selection La ope a a eR ke Enabling of timer operation Stops operation clears the counter to O 1 Enables operation Caution Setting the TCL801 bit and TCL800 bit is prohibited when TCE80 is set to 1 Remark fxr Oscillation frequency of the clock supplied to peripheral hardware 2 Interval time setting The interval time is set by using 8 bit compare register 80 CR80 e Interval time N 1 fcNr Remark N CR80 setting value OOH to FFH fent Count clock frequency of 8 bit timer 80 Figure 4 2 Format of 8 bit Compare Register 80 CR80 CR80 ee ee Caution Rewriting the CR80 register value during timer count operation is prohibited Application Note U18864EJ2V
40. ss in order to handle chattering during switch input INTP1 interrupt generation in this sample program INTTM80 interrupts can be continuously counted even during chattering detection by using INT TM80 interrupts for chattering detection Consequently offsets of the LED blinking cycle which are caused by switch input can be suppressed e Chattering detection time Tc T T x M 1 Remark T INTTM80 interrupt cycle T Time from the start of INTP1 edge detection until the first INTTM80 is generated after INTP1 edge detection 0 lt T lt T M Number of INTTM80 interrupts after INTP1 edge detection When set such that T x M 1 10 ms c T 10 ms 0 lt T lt T therefore 10 ms lt Tc lt T 10 ms Y Chattering detection time Tc 10 ms Calculation example When the interrupt cycle T is 2 ms refer to the calculation example in 1 Setting the LED blinking cycle and the number of INT TM80 interrupts after INTP1 edge detection M is 6 Tc ZT Tx M 1 T 2ms x 6 1 1T 10ms 0 lt T lt 2 ms therefore 10 ms lt Tc lt 12 ms Y Chattering detection time Tc 10 ms The following table shows the correspondence between the interrupt cycles during switch input and the number of INTTM80 interrupts after INTP1 edge detection in this sample program LED Blinking Cycle Interrupt Cycle Number of INT TM80 Interrupts Chattering Detection Time After INTP 1 Detection Abutis 1s Abut2ms
41. terrupt Cycle LED Blinking Cycle 249 About 2 ms About 1s 249 1 125 kHz about 2 ms x 250 x 2 About 1 ms About 0 5 s 124 1 125 kHz about 1 ms x 250 x 2 About 0 504 ms About 0 252 s 62 1 125 kHz about 504 us x 250 x 2 About 0 256 ms About 0 128 s 31 1 125 kHz about 256 us x 250 x 2 Note The blinking cycle from the zeroth switch input is repeated after the fourth switch input 16 Application Note U18864EJ2VOAN CHAPTER 4 SETTING METHODS Figure 4 3 Timing Chart Example of the LED Blinking Cycle When the LEDs Blink at a Cycle of About 1 s About 8 us EN Count clock 125 kHz EMEN PLE LE LE LP LE LI LI Le Interval time About 2 ms About 8 us x 250 INTTM80 Number of interrupts 1 Number of interrupts 2 P20 output Count clock 125 kHz INTTM80 Number of interrupts 250 gt Number of interrupts 1 Number of interrupts 250 gt Clears the count for the number of interrupts Clears the count for the number of interrupts P20 output LED output reversal cycle About 0 5 s About 2 ms x 250 Remark The CR80 register setting value is 124 62 and 31 when the LEDs blink at respective cycles of about 1 2 s 1 4 s and 1 8 s Application Note U18864EJ2VOAN 17 18 CHAPTER 4 SETTING METHODS 2 Setting the chattering detection time The generation of 8 bit timer 80 interrupts INTTM80 is counted to remove chattering of 10 ms or le
42. ty rights of third parties by or arising from the use of NEC Electronics products listed in this document or any other liability arising from the use of such products No license express implied or otherwise is granted under any patents copyrights or other intellectual property rights of NEC Electronics or others e Descriptions of circuits software and other related information in this document are provided for illustrative purposes in semiconductor product operation and application examples The incorporation of these circuits software and information in the design of a customer s equipment shall be done under the full responsibility of the customer NEC Electronics assumes no responsibility for any losses incurred by customers or third parties arising from the use of these circuits software and information e While NEC Electronics endeavors to enhance the quality reliability and safety of NEC Electronics products customers agree and acknowledge that the possibility of defects thereof cannot be eliminated entirely To minimize risks of damage to property or injury including death to persons arising from defects in NEC Electronics products customers must incorporate sufficient safety measures in their design such as redundancy fire containment and anti failure features e NEC Electronics products are classified into the following three quality grades Standard Special and Specific The Specific quality grade applies only to NEC Elect
43. uantum Plaza No 27 ZhiChunLu Haidian District Beijing 100083 P R China Tel 010 8235 1155 http www cn necel com Shanghai Branch Room 2509 2510 Bank of China Tower 200 Yincheng Road Central Pudong New Area Shanghai P H China P C 200120 Tel 021 5888 5400 http www cn necel com Shenzhen Branch Unit 01 39 F Excellence Times Square Building No 4068 Yi Tian Road Futian District Shenzhen P R China P C 518048 Tel 0755 8282 9800 http www cn necel com NEC Electronics Hong Kong Ltd Unit 1601 1613 16 F Tower 2 Grand Century Place 193 Prince Edward Road West Mongkok Kowloon Hong Kong Tel 2886 9318 http www hk necel com NEC Electronics Taiwan Ltd 7F No 363 Fu Shing North Road Taipei Taiwan R O C Tel 02 8175 9600 http www tw necel com NEC Electronics Singapore Pte Ltd 238A Thomson Road 12 08 Novena Square Singapore 307684 Tel 6253 8311 http www sg necel com NEC Electronics Korea Ltd 11F Samik Lavied or Bldg 720 2 Yeoksam Dong Kangnam Ku Seoul 135 080 Korea Tel 02 558 3737 http www kr necel com G0706
44. unting the number Of TINTIM80 umterfupts const unsigned char g ucchat 4 541 10T 1 20T1 4041 8 bit constant table for removing chattering const unsconed char g uccR5Udarta 4 1250 1 125 1 03 1 32 91 5 8 bit constant table for LED blinking base time KK KK KKK kk Kk Kk KA KA KA Kk kA kA KK AX Kk kA Kk KK KK kA kA KK KK KK kA kA kA kA kck k ck ck kk kk kck ck ko ko Initialization after RESET HK I kck kk kk kk kk ck kck kk kk AX kA ck kk kk kk k kc kA k kk kk kck kck k kc k kk kk kck kA ck kk kk k ck ck ck kA kA kA kk kk void hdwinit void unsigned char ucCnt200us 8 bit variable for 200 us wait Initialize the watchdog timer WDTM 0b01110111 Stop the watchdog timer operation jw Sep the Glock Tr 34 Application Note U18864EJ2VOAN APPENDIX A PROGRAM LIST PCC 0b00000000 The clock supplied to the CPU fcpu fxp fx 4 2 MHz LSRCM 0500000001 Stop the oscillation of the low speed internal oscillator Check the reset source if RESF amp 0b00000001 Omit subsequent LVI related processing during LVL preset Set low voltage detection LVIS 0500000000 Set the low voltage detection level VEVD To Ags V O M UNI LVION 1 Enable the low voltage detector Op ration for QuoCcnt200u0s O uecne200us 9s uccnt200usTJq 1 Fx Wait of about 00 we 47 NOP j while LVIF 4 A Wart FOr VDD 23 MVE v NOP j
Download Pdf Manuals
Related Search
Related Contents
取扱説明書 F905i 取扱説明書 Dell M1000E User's Manual OWNER`S MANUAL Superclip & Superclip 2 User Manual Superclip Trevi DLX 670 商品カタログはこちら Copyright © All rights reserved.
Failed to retrieve file