NEC 78K0S/K 1+ Series Application Note

Led lighting switch control sample program (initial settings)
Hide thumbs Also See for 78K0S/K 1+ Series:

Advertisement

Quick Links

Application Note
78K0S/Kx1+
Sample Program (Initial Settings)
LED Lighting Switch Control
This document summarizes the initial settings for the sample program and describes basic initial settings for
the microcontroller. In the sample program, the two switch inputs and lighting of the three LEDs are
controlled, after the basic initial settings for the microcontroller, such as selecting the clock frequency or I/O
port, have been performed.
Target devices
78K0S/KA1+ microcontroller
78K0S/KB1+ microcontroller
78K0S/KU1+ microcontroller
78K0S/KY1+ microcontroller
Document No.
U18752EJ2V0AN00 (2nd edition)
Date Published September 2008 NS
Printed in Japan
2007
CHAPTER 1 OVERVIEW ....................................................................................3
CHAPTER 2 CIRCUIT DIAGRAM ......................................................................4
2.1
Circuit Diagram ........................................................................................4
2.2
Peripheral Hardware ................................................................................4
CHAPTER 3 SOFTWARE ...................................................................................5
3.1
File Configuration.....................................................................................5
3.2
Internal Peripheral Functions to Be Used ................................................6
3.3
Initial Settings and Operation Overview...................................................6
3.4
Flow Chart ...............................................................................................7
CHAPTER 4 SETTING METHODS .....................................................................8
4.1
Option Byte Setting ..................................................................................8
4.2
Vector Table Setting ..............................................................................12
4.3
Stack Pointer Setting .............................................................................13
4.4
Watchdog Timer Setting ........................................................................14
4.5
Clock Setting..........................................................................................17
4.6
Port Setting ............................................................................................23
4.7
Main Processing ....................................................................................27
5.1
Building the Sample Program ................................................................29
5.2
Operation with SM+ ...............................................................................31
CHAPTER 6 RELATED DOCUMENTS.............................................................35
APPENDIX A PROGRAM LIST.........................................................................36
APPENDIX B REVISION HISTORY ..................................................................43
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 (Initial Settings) LED Lighting Switch Control This document summarizes the initial settings for the sample program and describes basic initial settings for the microcontroller. In the sample program, the two switch inputs and lighting of the three LEDs are controlled, after the basic initial settings for the microcontroller, such as selecting the clock frequency or I/O port, have been performed.
  • 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 In this sample program, the basic initial settings for the 78K0S/Kx1+ microcontroller, such as setting the option byte, selecting the clock frequency, and setting I/O ports are performed. In the main processing operation after completion of the initial settings, the lighting of the three LEDs is controlled by using the two switch inputs. (1) Main contents of initial settings •...
  • Page 4: 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. RESET LED3 78K0S/Kx1+ microcontroller LED2 LED1 Cautions 1. Connect the AV pin directly to V (only for the 78K0S/KA1+ and 78K0S/KB1+ microcontrollers).
  • Page 5: 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 6: 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. • Input ports (for switch inputs): P40, P43 • Output ports (for lighting LEDs): P20, P21, P22 Initial Settings and Operation Overview In this sample program, the selection of the clock frequency, setting of the I/O ports, and the like are performed in the initial settings.
  • Page 7: Flow Chart

    CHAPTER 3 SOFTWARE Flow Chart A flow chart for the sample program is shown below. Start Option byte setting Stack pointer setting Stopping watchdog timer operation Initial settings Setting the CPU clock frequency and peripheral hardware clock frequency to 2 MHz Stopping the oscillation of the low-speed internal oscillator I/O port setting...
  • Page 8: Chapter 4 Setting Methods

    CHAPTER 4 SETTING METHODS This chapter describes how to set the option byte, vector table, stack pointer, watchdog timer, clock frequency, and ports, as well as the main processing. For how to set registers, refer to the user’s manual of each product (78K0S/KU1+, 78K0S/KY1+, 78K0S/KA1+, 78K0S/KB1+).
  • Page 9 CHAPTER 4 SETTING METHODS Note 2. If the high-speed internal oscillation clock or an external clock input is selected as the system clock, no oscillation stabilization time is required, so the setting becomes invalid (don’t care). Caution Bits 4 and 7 must be set to 1. Remark x: don’t care [Example 1] The high-speed internal oscillation clock is used, used as the RESET pin, and the low-speed internal...
  • Page 10 CHAPTER 4 SETTING METHODS [Example 2] A crystal or ceramic oscillation clock is used, used as the RESET pin, the low-speed internal oscillator can be stopped, and the oscillation stabilization time is minimized (2 /fx). (This is the same as in Example 1, except for the underlined parts.) Address: 0080H Control of low-speed internal oscillator oscillation Oscillation is stopped by software setting...
  • Page 11 CHAPTER 4 SETTING METHODS [Example 3] A crystal or ceramic oscillation clock is used, used as the P34 pin, the low-speed internal oscillator can be stopped, and the oscillation stabilization time is minimized (2 (This is the same as in Example 2, except for the underlined part.) Address: 0080H Control of low-speed internal oscillator oscillation Oscillation is stopped by software setting...
  • Page 12: Vector Table Setting

    CHAPTER 4 SETTING METHODS Vector Table Setting In the vector table area, the program start address, which is used when branching occurs due to the generation of resets and various interrupt requests, is stored. In this sample program, interrupt servicing is not performed, so only the reset vector which is used during reset start is set.
  • Page 13: Stack Pointer Setting

    CHAPTER 4 SETTING METHODS Stack Pointer Setting A stack area is a memory area in which data, such as of program counters, register values, and PSW (program status word) is temporarily stored. A stack area can be specified only to the internal high-speed RAM area. The start address of this stack area is set with a stack pointer to secure the stack area.
  • Page 14: Watchdog Timer Setting

    CHAPTER 4 SETTING METHODS Watchdog Timer Setting The WDTM register is used to select the operation clock for the watchdog timer and the overflow time. In this sample program, the watchdog timer is not used for program loop detection, so the WDTM register is set as described in [Example 1], mentioned later.
  • Page 15 CHAPTER 4 SETTING METHODS [Example 1] Watchdog timer stop (same as in the sample program setting) WDTM Overflow time setting (Setting is invalid, because watchdog timer operation is stopped.) Operation clock selection Note Watchdog timer operation stop * In this sample program, the watchdog timer is not used for program loop detection, so it is set to operation stop.
  • Page 16 For details, refer to the CC78K0S Language User’s Manual Processing to be executed first under Programming on the NEC Electronics FAQ Web page. Application Note U18752EJ2V0AN...
  • Page 17: Clock Setting

    CHAPTER 4 SETTING METHODS Clock Setting (1) Clock frequency setting The CPU clock frequency (f ) and the frequency of the clock supplied to peripheral hardware (f ) are generated by dividing the frequency of the system clock set with the option byte. The PPCC and PCC registers are used to select the CPU clock frequency (f ) and the frequency of the clock supplied to peripheral hardware (f...
  • Page 18 CHAPTER 4 SETTING METHODS [Example 1] f (This is the same as in the sample program setting. In this sample program, “high-speed internal oscillation clock (8 MHz (TYP.))” is selected as the system clock (f ) by the option byte setting, so the CPU clock frequency (f ) and peripheral hardware clock frequency (f ) are 2 MHz (= 8 MHz/4).)
  • Page 19 CHAPTER 4 SETTING METHODS [Example 2] f /8, f (When “high-speed internal oscillation clock (8 MHz (TYP.))” is selected as the system clock (f ) by the option byte setting, the CPU clock frequency (f ) is 1 MHz (= 8 MHz/8) and the peripheral hardware clock frequency (f ) is 4 MHz (= 8 MHz/2).) PPCC...
  • Page 20 CHAPTER 4 SETTING METHODS (2) Low-speed internal oscillator setting The low-speed internal oscillation clock is used as the clock source for the watchdog timer and 8-bit timer H1. The LSRCM register is used to oscillate or stop the low-speed internal oscillator. In this sample program, the low-speed internal oscillation clock is not used, so the LSRCM register is set as described in [Example...
  • Page 21 CHAPTER 4 SETTING METHODS [Example 2] Oscillation of the low-speed internal oscillator LSRCM Note Oscillation/stop of low-speed internal oscillator Oscillation Note When oscillation of the low-speed internal oscillator is set to “Cannot be stopped” by using the option byte, the LSRCM setting is invalid (don’t care). For details, refer to 4.1 Option Byte Setting.
  • Page 22 CHAPTER 4 SETTING METHODS (3) Setting of the oscillation stabilization time after releasing the STOP mode (when crystal or ceramic oscillation is used for the system clock source) The OSTS register is used to set the oscillation stabilization time after releasing the STOP mode. The OSTS setting is valid only when crystal or ceramic oscillation is used for the system clock source.
  • Page 23: Port Setting

    CHAPTER 4 SETTING METHODS Port Setting Caution The on-chip ports vary, depending on each product, so the ports to be set also vary. 78K0S/KA1+ 78K0S/KB1+ 78K0S/KU1+ 78K0S/KY1+ − − − Port 0 P00 to P03 Port 2 P20 to P23 P20 to P23 P20 to P23 P20 to P23...
  • Page 24 CHAPTER 4 SETTING METHODS (3) Setting the connection of internal pull-up resistors to input ports The PUxx registers are used to set whether internal pull-up resistors are to be connected to the input ports. Internal pull-up resistors are not connected after reset release. The PUxx format is described, taking the PU2 register as an example.
  • Page 25 CHAPTER 4 SETTING METHODS [Example 2] • Setting P40 and P43 as input ports • Setting internal pull-up resistors to be connected to P40 and P43 (Same as in the sample program setting) • 78K0S/KB1+, 78K0S/KY1+ Selection of the P40 and P43 pin I/O modes Input mode •...
  • Page 26 CHAPTER 4 SETTING METHODS • Assembly language PM4, #00001001B PU4, #00001001B • C language PM4 = 0b00001001; PU4 = 0b00001001; Application Note U18752EJ2V0AN...
  • Page 27: Main Processing

    CHAPTER 4 SETTING METHODS Main Processing The following operations are performed with the main processing in assembly language. <1> The P4 register data is read. <2> Among the read 8-bit data, bits except those of the input ports (P40, P43) are cleared to 0. <3>...
  • Page 28 CHAPTER 4 SETTING METHODS The main processing in C language operates similarly to that in assembly language. In C language, the correspondence between the input data and output data is set as an array. /******************************************************************************* Ten units of data are defined within the brackets Main loop wherein output data is set.
  • 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 that has been downloaded by selecting the icon. <R> Caution System simulator SM+ for 78K0S/Kx1+ is not supported with the 78K0S/KU1+ microcontroller (as of July 2008).
  • Page 30 CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM+ (1) Start PM+. (2) Select “initial.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].
  • Page 31: Operation With Sm

    CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM+ (4) Click ([Build] button). When the source files are built normally, the message “I3500: Build completed normally.” will be displayed. (5) Click the [OK] button in the message dialog box. A HEX file for flash memory writing will be created. Click Click A HEX file for flash memory writing will be generated.
  • Page 32 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.) (3) Click ([Restart] button).
  • Page 33 CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM+ (4) Click the [SW1] and [SW2] buttons in the I/O panel window, during program execution. Check the lighting of [LED1] to [LED3] in the I/O panel window, as well as the waveforms in the timing chart window change, depending on the combination of the [SW1] and [SW2] buttons.
  • Page 34 CHAPTER 5 OPERATION CHECK USING SYSTEM SIMULATOR SM+ [Supplement] The changes in the data values of ports 2 and 4 can be checked by using the SM+ watch function. <1> Select [Watch] from the [Browse] menu to open the [Watch] window. <2>...
  • 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 <R>...
  • 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 ;******************************************************************************* Initialization ;******************************************************************************* ;<<History>> 2007.4.-- Release ;******************************************************************************* ;<<Overview>> ; This sample program initializes the microcontroller by setting functions ;...
  • Page 37 APPENDIX A PROGRAM LIST ;=============================================================================== Vector table ;=============================================================================== XVCT CSEG 0000H RESET_START ;(00) RESET RESET_START ;(02) -- RESET_START ;(04) -- RESET_START ;(06) INTLVI RESET_START ;(08) INTP0 RESET_START ;(0A) INTP1 RESET_START ;(0C) INTTMH1 RESET_START ;(0E) INTTM000 RESET_START ;(10) INTTM010 RESET_START ;(12) INTAD RESET_START ;(14) -- RESET_START...
  • Page 38 APPENDIX A PROGRAM LIST ;******************************************************************************* XMAIN CSEG UNIT RESET_START: ;------------------------------------------------------------------------------- Initialize the stack pointer ;------------------------------------------------------------------------------- MOVW #STACKTOP MOVW ; Set the stack pointer at FF00H ;------------------------------------------------------------------------------- Initialize the watchdog timer ;------------------------------------------------------------------------------- WDTM, #01110111B ; Stop the watchdog timer operation ;------------------------------------------------------------------------------- Initialize the clock generators ;------------------------------------------------------------------------------- PPCC, #00000010B...
  • Page 39 APPENDIX A PROGRAM LIST Initialize the port 13 ;------------------------------------------------------------------------------- P13, #00000001B ; Set output latch of P130 as high ;------------------------------------------------------------------------------- Initialize the general-purpose register ;------------------------------------------------------------------------------- MOVW #LEDDATA ; Set the table address to the HL register ;******************************************************************************* Main loop ;******************************************************************************* MAIN_LOOP: A, P4 ;...
  • Page 40 APPENDIX A PROGRAM LIST main.c (C language version) /***************************************************************************** NEC Electronics 78K0S/KB1+ ****************************************************************************** 78K0S/KB1+ Sample program ****************************************************************************** Initialization ****************************************************************************** <<History>> 2007.4.-- Release ****************************************************************************** <<Overview>> This sample program initializes the microcontroller by setting the functions such as clock frequency and the port to the input or output.
  • Page 41 APPENDIX A PROGRAM LIST /***************************************************************************** Initialization after RESET *****************************************************************************/ void hdwinit(void){ /*---------------------------------------------------------------------------- Initialize the watchdog timer ----------------------------------------------------------------------------*/ WDTM = 0b01110111; /* Stop the watchdog timer operation */ /*---------------------------------------------------------------------------- Initialize the clock generators ----------------------------------------------------------------------------*/ PPCC = 0b00000010; /* The clock supplied to the peripheral */ /* hardware (fxp) = fx/4 (= 2MHz) */ = 0b00000000;...
  • Page 42 APPENDIX A PROGRAM LIST ----------------------------------------------------------------------------*/ = 0b00000001; /* Set output latches of P120-P123 as */ /* high */ /***************************************************************************** Main loop *****************************************************************************/ void main(void){ const unsigned char OUTDATA[10] = {0x03,0x05,0x07,0x07,0x07,0x07,0x07, 0x07,0x06,0x07}; /* Array of LED output pattern */ unsigned char INDATA; /* Switch-input variable */ while(1){ INDATA = P4 &...
  • Page 43: Appendix B Revision History

    APPENDIX B REVISION HISTORY The mark “<R>” shows major revised points. The revised points can be easily searched by copying an “<R>” in the PDF file and specifying it in the “Find what.” field. Edition Date Published Page Revision − −...
  • Page 44 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