NEC 78K0S/K 1+ Series Application Note
NEC 78K0S/K 1+ Series Application Note

NEC 78K0S/K 1+ Series Application Note

Sample program (16-bit timer/event counter 00) interval timer
Hide thumbs Also See for 78K0S/K 1+ Series:

Advertisement

Quick Links

Application Note
78K0S/Kx1+
Sample Program (16-bit Timer/Event Counter 00)
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 16-bit timer/event counter 00. In the sample program, the LEDs are blinked at fixed cycles
by using the interval timer function of 16-bit timer/event counter 00. Furthermore, the blinking cycle of the LEDs is
changed in accordance with the number of switch inputs.
Target devices
78K0S/KA1+ microcontroller
78K0S/KB1+ microcontroller
78K0S/KU1+ microcontroller
78K0S/KY1+ microcontroller
Document No.
U18887EJ1V0AN00 (1st edition)
Date Published November 2007 N
Printed in Japan
2007
CHAPTER 1 OVERVIEW....................................................................................... 3
1.1
Main Contents of the Initial Settings............................................................ 3
1.2
Contents Following the Main Loop.............................................................. 4
CHAPTER 2 CIRCUIT DIAGRAM ....................................................................... 5
2.1
Circuit Diagram ........................................................................................... 5
2.2
Peripheral Hardware ................................................................................... 5
CHAPTER 3 SOFTWARE .................................................................................... 6
3.1
File Configuration ........................................................................................ 6
3.2
Internal Peripheral Functions to Be Used ................................................... 7
3.3
Initial Settings and Operation Overview ...................................................... 7
3.4
Flow Charts ................................................................................................. 9
CHAPTER 4 SETTING METHODS.................................................................... 10
4.1
4.2
5.1
Building the Sample Program ................................................................... 29
5.2
Operation with SM+................................................................................... 30
CHAPTER 6 RELATED DOCUMENTS ............................................................. 35
APPENDIX A PROGRAM LIST......................................................................... 36
APPENDIX B REVISION HISTORY .................................................................. 48
CONTENTS

Advertisement

Table of Contents
loading

Summary of Contents for NEC 78K0S/K 1+ Series

  • Page 1: Table Of Contents

    Application Note 78K0S/Kx1+ Sample Program (16-bit Timer/Event Counter 00) 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 16-bit timer/event counter 00. In the sample program, the LEDs are blinked at fixed cycles by using the interval timer function of 16-bit timer/event counter 00.
  • Page 2 NEC Electronics does not assume any liability for infringement of patents, copyrights or other intellectual property 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.
  • Page 3: Chapter 1 Overview

    CHAPTER 1 OVERVIEW An example of using the interval timer function of 16-bit timer/event counter 00 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.
  • Page 4: Contents Following The Main Loop

    CHAPTER 1 OVERVIEW Contents Following the Main Loop The LEDs are blinked at fixed cycles by using the generation of a 16-bit timer/event counter 00 interrupt (INTTM000), 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.
  • Page 5: Chapter 2 Circuit Diagram

    CHAPTER 2 CIRCUIT DIAGRAM This chapter describes a circuit diagram and the peripheral hardware to be used in this sample program. Circuit Diagram A circuit diagram is shown below. Note 1 RESET 78K0S/Kx1+ microcontroller INTP1 Note 2 Notes 1. Use this in a voltage range of 4.5 V ≤ V ≤...
  • Page 6: Chapter 3 Software

    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. File Configuration The following table shows the file configuration of the compressed file to be downloaded.
  • Page 7: Internal Peripheral Functions To Be Used

    CHAPTER 3 SOFTWARE Internal Peripheral Functions to Be Used The following internal peripheral functions of the microcontroller are used in this sample program. • Interval timer function: 16-bit timer/event counter 00 • V < V detection: Low-voltage detector (LVI) • Switch input: Note INTP1 (external interrupt)
  • Page 8 CHAPTER 3 SOFTWARE The details are described in the status transition diagram shown below. Initial settings 1 • Referencing the option byte • Selecting the high-speed internal oscillator as the system clock source • The low-speed internal oscillator can be stopped by software •...
  • Page 9: Flow Charts

    CHAPTER 3 SOFTWARE Flow Charts The flow charts for the sample program are shown below. <Processing after reset release> <Vector interrupt INTP1> <Vector interrupt INTTM000> Reset start Vector interrupt INTTM000 start Vector interrupt INTP1 start Note Referencing the option byte INTTM000 interrupt Stack pointer setting Saving the AX register data...
  • Page 10: Chapter 4 Setting Methods

    CHAPTER 4 SETTING METHODS This chapter describes the interval timer function of 16-bit timer/event counter 00. For other initial settings, refer to the 78K0S/Kx1+ Sample Program (Initial Settings) LED Lighting Switch Control Application Note. For interrupt, refer to the 78K0S/Kx1+ Sample Program (Interrupt) External Interrupt Generated by Switch Input Application Note.
  • Page 11 CHAPTER 4 SETTING METHODS <Example of the basic operation setting procedure when using 16-bit timer/event counter 00 as an interval timer> <1> Setting the CRC00 register <2> Setting an arbitrary value to the CR000 register <3> Setting the count clock using the PRM00 register <4>...
  • Page 12 CHAPTER 4 SETTING METHODS (2) Setting the CR000 register This register has the functions of both a capture register and a compare register. Figure 4-2. Format of 16-bit Timer Capture/Compare Register 000 (CR000) CR000 When using CR000 as a compare register The value set to CR000 is constantly compared with the 16-bit timer counter 00 (TM00) count value, and an interrupt request (INTTM000) is generated if they match.
  • Page 13 CHAPTER 4 SETTING METHODS (3) Setting the PRM00 register This register is used to set the count clock of the TM00 counter and the valid edges of the TI000 and TI010 pin inputs. Figure 4-3. Format of Prescaler Mode Register 00 (PRM00) PRM00 ES110 ES100 ES010 ES000 PRM001 PRM000...
  • Page 14 CHAPTER 4 SETTING METHODS Cautions 4. To use the valid edge of TI000 with the count clock, it is sampled with f to eliminate noise. The capture operation is not performed until the valid edge is sampled and the valid level is detected twice, thus eliminating noise with a short pulse width.
  • Page 15 CHAPTER 4 SETTING METHODS Cautions 1. The timer operation must be stopped before setting bits other than OSPT00. 2. If LVS00 and LVR00 are read, 0 is read. 3. OSPT00 is automatically cleared after data is set, so 0 is read. 4.
  • Page 16 CHAPTER 4 SETTING METHODS Cautions 1. The operation of the TM00 counter starts when values other than 0 and 0 (operation stop mode) are set to TMC002 and TMC003, respectively. To stop the operation, set TMC002 and TMC003 to 0 and 0, respectively. 2.
  • Page 17 CHAPTER 4 SETTING METHODS [Example 1] When setting the interval cycle to 2.016 ms and using 16-bit timer/event counter 00 as an interval timer (Count clock = f = 8 MHz), no timer output (TO00 pin output)) (Same contents as in this sample program source) (1) Register settings <1>...
  • Page 18 CHAPTER 4 SETTING METHODS <4> TOC00 Timer output control Disables output. Timer F/F control upon match between CR000 and TM00 Disables inversion operation. Timer output F/F status setting Does not change. Timer F/F control upon match between CR010 and TM00 Disables inversion operation.
  • Page 19 CHAPTER 4 SETTING METHODS (2) Sample program In the example below, “x” in (1) Register settings is set to “0”. <1> Assembly language CRC00, #00000000B MOVW CR000, #62 PRM00, #00000010B TOC00, #00000000B TMC00, #00001100B <2> C language CRC00 = 0b00000000; CR000 = 62;...
  • Page 20 CHAPTER 4 SETTING METHODS μ [Example 2] When setting the interval cycle to 50 s and outputting from the TO00 pin a square wave with a μ cycle of 100 s (10 kHz) (Count clock = f = 8 MHz), initial value of TO00 output is low level) (1) Register settings <1>...
  • Page 21 CHAPTER 4 SETTING METHODS <4> TOC00 Timer output control Enables output. Timer F/F control upon match between CR000 and TM00 Enables inversion operation. Timer output F/F status setting Resets (0) timer output F/F. Timer F/F control upon match between CR010 and TM00 Disables inversion operation.
  • Page 22 CHAPTER 4 SETTING METHODS (2) Sample program In the example below, “x” in (1) Register settings is set to “0”. <1> Assembly language (when using the 78K0S/KA1+ and 78K0S/KB1+ microcontrollers) CLR1 P3.1 CLR1 PM3.1 CRC00, #00000000B MOVW CR000, #99 PRM00, #00000001B TOC00, #00000111B TMC00, #00001100B <2>...
  • Page 23 CHAPTER 4 SETTING METHODS [Excerpt from this sample program source] An excerpt from APPENDIX A PROGRAM LIST, which is related to the 16-bit timer/event counter 00 function, is shown below (same contents as in [Example 1] mentioned above). (1) Assembly language XMAIN CSEG UNIT RESET_START:...
  • Page 24 CHAPTER 4 SETTING METHODS (2) C language void hdwinit(void){ unsigned char ucCnt200us; /* 8-bit variable for 200 us wait */ • Setting the interval Setting the operation mode • of CR000 as a compare time • register CRC00 = 0b00000000; /* Use CR000 as a compare register */ Setting the count clock...
  • Page 25: Setting The Led Blinking Cycle And Chattering Detection Time

    CHAPTER 4 SETTING METHODS 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 16-bit timer/event counter 00 interrupts (INTTM000) in this sample program.
  • Page 26 CHAPTER 4 SETTING METHODS Figure 4-6. Timing Chart Example of the LED Blinking Cycle (When the LEDs Blink at a Cycle of About 1 s) μ About 32 s Count clock (31.25 kHz) Enables timer operation TM00 Clear Clear CR000 Interval time: About 2 ms μ...
  • Page 27 CHAPTER 4 SETTING METHODS (2) Setting the chattering detection time The generation of 16-bit timer/event counter 00 interrupts (INTTM000) is counted to remove chattering of 10 ms or less, in order to handle chattering during switch input (INTP1 interrupt generation) in this sample program.
  • Page 28 CHAPTER 4 SETTING METHODS Figure 4-7. Timing Chart Example of Chattering Detection (When the LEDs Blink at Cycles of About 1 s During Switch Input) μ About 32 s Count clock (31.25 kHz) TM00 Clear Clear Clear CR001 Interval time: About 2 ms (= About 32 s ×...
  • Page 29: Chapter 5 Operation Check Using System Simulator Sm

    CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM+ This chapter describes how the sample program operates with system simulator SM+ for 78K0S/Kx1+, by using the assembly language file (source files + project file) that has been downloaded by selecting the icon.
  • Page 30: Operation With Sm

    CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM+ ([Build → Debug] button). When the “main.asm” and “op.asm” source files are built normally, the (4) Click message “I3500: Build completed normally.” will be displayed. (5) Click the [OK] button in the message window to automatically start SM+. Click Click SM+ starts automatically.
  • Page 31 CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM+ When SM+ is started by clicking [Build → Debug] on PM+ (refer to 5.1), the following screen will be displayed. (This is a screen example when the assembly language source file is used.) (2) Click ([Restart] button).
  • Page 32 CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM+ (3) 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.
  • Page 33 CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM+ [Supplement 1] The changes in the data value of the CR000 register can be checked by using the SM+ watch function. <1> Click the [Watch] button in the source window to open the [Watch] window. <2>...
  • Page 34 CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM+ [Supplement 2] 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>...
  • Page 35: Chapter 6 Related Documents

    CHAPTER 6 RELATED DOCUMENTS Document Name Japanese/English 78K0S/KU1+ User’s Manual 78K0S/KY1+ User’s Manual 78K0S/KA1+ User’s Manual 78K0S/KB1+ User’s Manual 78K/0S Series Instructions User’s Manual RA78K0S Assembler Package User’s Manual Language Operation CC78K0S C Compiler User’s Manual Language Operation PM+ Project Manager User’s Manual SM+ System Simulator Operation User’s Manual 78K0S/KA1+ Simplified Flash Writing Manual MINICUBE2 Information Sample Program Startup Guide...
  • Page 36: Appendix A Program List

    APPENDIX A PROGRAM LIST As a program list example, the 78K0S/KB1+ microcontroller source program is shown below. main.asm (Assembly language version) ;***************************************************************************** NEC Electronics 78K0S/KB1+ ;***************************************************************************** 78K0S/KB1+ Sample program ;***************************************************************************** 16-bit timer 00 (interval timer) ;***************************************************************************** ;<<History>> 2007.7.-- Release ;***************************************************************************** ;<<Overview>>...
  • Page 37 APPENDIX A PROGRAM LIST 0 times 1 second | 1 time 1/2 second | 2 times 1/4 second | 3 times 1/8 second | +--------------------------+ # The blinking cycle from the zeroth switch input is repeated after the fourth switch input. ;<<I/O port settings>>...
  • Page 38 APPENDIX A PROGRAM LIST 20+1 ; Count value for handling chattering (for 0.5 ms interval) 40+1 ; Count value for handling chattering (for 0.25 ms interval) ;============================================================================= Define the RAM ;============================================================================= XRAM DSEG SADDR CNT_TM000: ; For counting INTTM000 interrupt ;============================================================================= Define the memory stack area ;=============================================================================...
  • Page 39 APPENDIX A PROGRAM LIST SET1 LVION ; Enable the low-voltage detector operation ; Assign the 200 us wait count value ;----- 200 us wait ----- WAIT_200US: $WAIT_200US ; 0.5[us/clk] x 10[clk] x 40[count] = 200[us] ;----- VDD >= VLVI wait processing ----- WAIT_LVI: LVIF, $WAIT_LVI...
  • Page 40 APPENDIX A PROGRAM LIST P13, #00000001B ; Set output latch of P130 as high ;----------------------------------------------------------------------------- Initialize the general-purpose register and RAM ;----------------------------------------------------------------------------- CNT_TM000, #250 ; Initialize the number of INTTM000 interrupts MOVW #0100H ; Specify the table address to HL (used for INTP1 interrupt) ;----------------------------------------------------------------------------- Set 16-bit timer 00...
  • Page 41 APPENDIX A PROGRAM LIST CALL !SUB_INTERRUPT_TM000 ; Service the INTTM000 interrupt ; Decrement the A register by 1 $WAIT_CHAT ; Branch if not A = 0 CLR1 PIF1 ; Clear the INTP1 interrupt request ;----- Identification of chattering detection ----- P4.3, $END_INTP1 ;...
  • Page 42 APPENDIX A PROGRAM LIST main.c (C language version) /***************************************************************************** NEC Electronics 78K0S/KB1+ ****************************************************************************** 78K0S/KB1+ Sample program ****************************************************************************** 16-bit timer 00 (interval timer) ****************************************************************************** <<History>> 2007.7.-- Release ****************************************************************************** <<Overview>> This sample program presents an example of using the interval timer function of 16-bit timer 00.
  • Page 43 APPENDIX A PROGRAM LIST # The blinking cycle from the zeroth switch input is repeated after the fourth switch input. <<I/O port settings>> Input: P43 Output: P00-P03, P20-P23, P30-P33, P40-P42, P44-P47, P120-P123, P130 # All unused ports are set as the output mode. *****************************************************************************/ /*============================================================================ Preprocessing directive (#pragma)
  • Page 44 APPENDIX A PROGRAM LIST ----------------------------------------------------------------------------*/ /* Initialize the watchdog timer */ WDTM = 0b01110111; /* Stop the watchdog timer operation */ /* Set the clock <1> */ = 0b00000000; /* The clock supplied to the CPU (fcpu) = fxp (= fx/4 = 2 MHz) */ LSRCM = 0b00000001;...
  • Page 45 APPENDIX A PROGRAM LIST ----------------------------------------------------------------------------*/ = 0b00000000; /* Set output latches of P40-P47 as low */ = 0b00001000; /* Connect on-chip pull-up resistor to P43 = 0b00001000; /* Set P40-P42 and P44-P47 as output mode, P43 as input mode */ /*---------------------------------------------------------------------------- Initialize the port 12 ----------------------------------------------------------------------------*/...
  • Page 46 APPENDIX A PROGRAM LIST External interrupt INTP1 *****************************************************************************/ __interrupt void fn_intp1(){ unsigned char ucChat; /* 8-bit variable for removing chattering for (ucChat = g_ucChat[g_ucSWcnt] ; ucChat > 0 ; ucChat--){ /* Wait of about 10 ms (for removing chattering) */ while (!TMIF000){ /* Wait for the INTTM000 interrupt request */ NOP();...
  • Page 47 APPENDIX A PROGRAM LIST return; op.asm (Common to assembly language and C language versions) ;============================================================================= Option byte ;============================================================================= OPBT CSEG 0080H 10011100B ; Option byte area |||| |||+---------- Low-speed internal oscillator can be stopped by software |++----------- High-speed internal oscillation clock (8 MHz) is selected for system clock source +------------- P34/RESET pin is used as RESET pin 11111111B...
  • Page 48: Appendix B Revision History

    APPENDIX B REVISION HISTORY Edition Date Published Page Revision − − 1st edition November 2007 Application Note U18887EJ1V0AN...
  • Page 49 Kawasaki, Kanagawa 211-8668, Japan Tel: 044-435-5111 http://www.necel.com/ [Asia & Oceania] [America] [Europe] NEC Electronics (China) Co., Ltd NEC Electronics America, Inc. NEC Electronics (Europe) GmbH 7th Floor, Quantum Plaza, No. 27 ZhiChunLu Haidian 2880 Scott Blvd. Arcadiastrasse 10 District, Beijing 100083, P.R.China Santa Clara, CA 95050-2554, U.S.A.

This manual is also suitable for:

78k0s/ka1+78k0s/kb1+78k0s/ku1+78k0s/ky1+

Table of Contents