Page 1
On April 1 , 2010, NEC Electronics Corporation merged with Renesas Technology Corporation, and Renesas Electronics Corporation took over all the business of both companies. Therefore, although the old company name remains in this document, it is a valid Renesas Electronics document. We appreciate your understanding.
Page 2
Renesas Electronics. Renesas Electronics shall not be in any way liable for any damages or losses incurred by you or third parties arising from the use of any Renesas Electronics product for an application categorized as “Specific”...
Application Note V850ES/Jx3 Sample Program (Initial Settings) LED Lighting Switch Control This document summarizes the initial settings for the sample program of the V850ES/Jx3 and describes the basic initial settings for the microcontroller. In the sample program, the lighting of two LEDs is controlled by using one switch input, after the basic initial settings for the peripheral functions of the microcontroller, such as selecting the clock frequency or I/O ports, have been performed.
Page 4
• The information in this document is current as of May, 2009. The information is subject to change without notice. For actual design-in, refer to the latest publications of NEC Electronics data sheets, etc., for the most up-to-date specifications of NEC Electronics products. Not all products and/or types are available in every country.
CHAPTER 1 OVERVIEW In this sample program, the basic initial settings for the V850ES/Jx3 microcontroller, such as selecting the clock frequency and setting the I/O ports, are performed. In the main processing operation after completing the initial settings, the lighting of two LEDs is controlled by using one switch input. Initial Settings <Main contents of initial settings>...
Page 6
CHAPTER 1 OVERVIEW Table 1-1. LED Lighting Patterns Note Switch (SW1) Input Count LED1 LED2 Note Inputs 0 to 3 are repeated from the fourth input. Caution See the product user’s manual (V850ES/Jx3) for cautions when using the device. [Column] What is chattering? Chattering is a phenomenon that an electric signal alternates between being on and off when a connection flip-flops mechanically immediately after a switch is switched.
CHAPTER 2 CIRCUIT DIAGRAM This chapter describes the circuit diagram and peripheral hardware to be used in this sample program. Circuit Diagram The circuit diagram is shown below. SW 1 LED2 PCM2 V850ES/Jx3 LED1 microcontroller PCM3 REGC FLMD0 RESET Cautions 1. Connect the EV , AV , and AV pins directly to V...
CHAPTER 2 CIRCUIT DIAGRAM Peripheral Hardware The peripheral hardware to be used is shown below. (1) Switch (SW1) This switch is used as an input to control the lighting of the LEDs. (2) LEDs (LED1, LED2) The LEDs are used as outputs corresponding to the number of switch inputs. Application Note U19837EJ1V0AN...
CHAPTER 3 SOFTWARE This chapter describes the file configuration of the compressed files to be downloaded, on-chip peripheral functions of the microcontroller to be used, and the initial settings and an operation overview of the sample program. A flowchart is also shown. File Configuration The following table shows the file configuration of the compressed files to be downloaded.
CHAPTER 3 SOFTWARE Initial Settings and Operation Overview In this sample program, the selection of the clock frequency and settings such as the setting for stopping the watchdog timer and the setting of the I/O ports are performed as the initial settings. After completing the initial settings, the lighting of two LEDs (LED1 and LED2) is controlled according to the number of switch (SW1) inputs.
CHAPTER 3 SOFTWARE Flowchart A flowchart for the sample program is shown below. Start Set the system wait control register to 2 clock Set on-chip debug mode register to normal operation mode Stop the internal oscillator Initial settings of Stop watchdog timer 2 peripheral functions to be used Multiply the CPU clock by 8 by...
CHAPTER 3 SOFTWARE Differences Between V850ES/JJ3 and V850ES/JG3 The V850ES/JJ3 is the V850ES/JG3 with its functions, such as I/Os, timer/counters, and serial interfaces, expanded. In this sample program, the port initialization range in I/O initialization differs. See APPENDIX A PROGRAM LIST for details of the sample program. ROMization In this sample program, ROMization information is copied after the on-chip peripheral functions are initialized.
Page 13
CHAPTER 3 SOFTWARE The section into which the ROMization information is to be stored (rompsec) will be automatically added immediately after the program area (.text) section. However, by checking “Create Object for ROM”, a code that indicates the same address as that of rompsec will be generated for the default label _S_romp defined by rompcrt.o, and the library libr.a, in which the copy function is stored, will be automatically linked.
CHAPTER 3 SOFTWARE Security ID The content of the flash memory can be protected from unauthorized reading by using a 10-byte ID code for authorization when executing on-chip debugging using an on-chip debug emulator. The debugger authorizes the ID by comparing it with the ID code preset to the 10 bytes from 0x0000070 to 0x0000079 in the internal flash memory area.
Page 15
CHAPTER 3 SOFTWARE Address 70 Address 79 • Bit 7 (0x0000079) of the 10 bytes of the ID code is the on-chip debug emulator use enable flag (0: Disables use, 1: Enables use). • When the on-chip debug emulator is started, the debugger requests ID entry. The debugger will be started if the ID code entered in the debugger matches the ID code embedded in addresses 0x0000070 to 0x0000079.
CHAPTER 3 SOFTWARE On-Chip debug with MINICUBE2 The following describes how to set an on-chip debug using MINICUBE2 with pins for CSIB0(SIB0, SOB0, SCKB0, and HS(PCM0)) as debug interfaces. These items need to be set in the user program or using the compiler options. See the following user’s manuals for details of how to set the items.
Page 17
CHAPTER 3 SOFTWARE Figure 3-1. Memory Spaces Where Debug Monitor Programs Are Allocated Internal RAM Internal ROM 0x3FFEFFF (16 bytes) 0x3FFEFF0 (2KB) Note 1 Internal RAM area Note 3 Access-prohibited area CSI0/UART receive Internal ROM interrupt vector (4 bytes) Note 2 area Interrupt vector for debugging (4 bytes)
Page 18
CHAPTER 3 SOFTWARE • How to secure areas In this sample program, the following shows examples for securing the area, using the CA850. Add the assemble source file and link directive code, as shown below. (a) Assemble source (Add the following code as an assemble source file.) -- Secures 2 KB space for monitor ROM section .section "MonitorROM", const .space 0x800, 0xff...
CHAPTER 3 SOFTWARE 3.8.2 Enable interrupts (EI) of Serial interfaces As serial interfaces(for example CSIB0) are used for communication between MINICUBE2 and the target device, forced breaks cannot be executed when interrupts issued for the serial interface, which is used for communication between MINICUBE2 and the target device, are masked.
CHAPTER 4 SETTING REGISTERS This chapter describes details of the system wait control register, on-chip debug mode register, watchdog timer 2, operation prohibition of DMA, internal system clock, PLL mode, pin function setting, and main processing. Set up for peripheral function that are not used in this sample program and stopped after reset release is not done. See the following user’s manuals for details of how to set registers.
CHAPTER 4 SETTING REGISTERS Setting System Wait Control Register (VSWC) The VSWC register is used to control wait cycles for bus access to the on-chip peripheral I/O registers. An on-chip peripheral I/O register can be accessed in three clocks (no wait cycles), but the V850ES/Jx3 requires wait cycles according to the operating frequency.
CHAPTER 4 SETTING REGISTERS Setting Special Registers The on-chip debug mode register (OCDM) and processor clock control register (PCC) are set in the initial setting procedure. These registers are special registers and must be written in a specific sequence. 4.2.1 Special registers Special registers are registers that are protected so that no illegal data will be written due to an infinite loop.
CHAPTER 4 SETTING REGISTERS 4.2.3 Disabling DMA operations DMA operations must be disabled in order to write data to a special register. DMA channel control registers 0 to 3 (DCHC0 to DCHC3) can be used to enable or disable DMA transfer for DMA channel n.
CHAPTER 4 SETTING REGISTERS Setting Normal Operation Mode for On-Chip Debug mode register Use the OCDM register to switch between normal operation mode and on-chip debug mode and to specify whether to use the alternate-function pin to which the on-chip debug function is assigned as an on-chip debug pin or as a normal port/peripheral function alternate-function pin.
Page 25
CHAPTER 4 SETTING REGISTERS The data set to the OCDM special register is 0x00. • Program example /* Specifies normal operation mode for OCDM. */ #pragma asm st.b r0, PRCMD st.b r0, OCDM #pragma endasm Application Note U19837EJ1V0AN...
CHAPTER 4 SETTING REGISTERS Setting Internal Oscillation Mode Register (RCM) The RCM register is an 8-bit register that is used to set the operation mode of the internal oscillator. In this sample program, the internal oscillator is stopped, because the watchdog timer is not used. This register can be read or written in 8-bit or 1-bit units.
CHAPTER 4 SETTING REGISTERS Setting Watchdog Timer 2 The WDTM2 register is used to set the overflow time and operating clock of watchdog timer 2. Watchdog timer 2 automatically starts in reset mode after reset is released. Write data to the WDTM2 register to specify the operation of watchdog timer 2.
CHAPTER 4 SETTING REGISTERS Clock Setting In this sample program, an example in which a 4 MHz ceramic or crystal resonator is connected to the X1 and X2 pins and the clock of the resonator is multiplied by 8 in PLL mode and used as the internal system clock (32 MHz) is shown.
Page 29
CHAPTER 4 SETTING REGISTERS The value set to PCC is 0x80. • Program example /* Set to not divide the clock. */ #pragma asm push r10 mov 0x80, r10 st.b r10, PRCMD st.b r10, PCC pop r10 #pragma endasm Application Note U19837EJ1V0AN...
CHAPTER 4 SETTING REGISTERS 4.6.2 Setting PLL control register (PLLCTL) The PLL control register (PLLCTL) is used to select the CPU operation clock. This register is an 8-bit register that controls the PLL. It can be read or written in 8-bit or 1-bit units. Reset sets this register to 0x01.
CHAPTER 4 SETTING REGISTERS 4.6.3 Lock register (LOCKR) The LOCKR register is used as a flag to check whether the PLL has stabilized (has been locked). This register is read-only, in 8-bit or 1- bit units. Reset sets this register to 0x01. This register becomes 0x00 when the oscillation stabilization time has elapsed after reset is released.
CHAPTER 4 SETTING REGISTERS 4.6.5 Usage To set to eight multiplication in PLL mode, Crock control register (CKC) is set to 0x0B (The CKC register is a special register. Data can be written to this register only in a combination of specific sequence.). First, stop the PLL, and then changing the multiplication factor for 4 to 8 by using the CKC register.
CHAPTER 4 SETTING REGISTERS Setting Ports The ports to be set vary, because the on-chip ports differ for each product. V850ES/JG3 V850ES/JJ3 Port 0 P02 to P06 P00 to P06 Port 1 P10, P11 P10 to P11 Port 3 P30 to P39 P30 to P39 Port 4 P40 to P42...
CHAPTER 4 SETTING REGISTERS 4.7.2 Port n mode register (PMn) The PMn register is used to specify input mode or output mode for each port. Each bit of the PMn register corresponds to one pin of port n and can be specified in 1-bit units. Reset sets this register to 0xFF.
Page 35
CHAPTER 4 SETTING REGISTERS [Example 1] • Setting P03 as an input port (V850ES/JJ3) Note Note PM06 PM05 PM04 PM03 PM02 PM01 PM00 P03 pin I/O selection Input mode Remark The value of nameless bit ( 7 bit ) is fixed by each products. Note V850ES/JG3 doesn't have P00 and P01, then PM01 and PM00 are fixed to 1.
Page 36
CHAPTER 4 SETTING REGISTERS [Example 2] • Setting the output latches of PCM2 and PCM3 to high-level output (V850ES/JJ3) • Setting PCM2 and PCM3 as output ports (V850ES/JJ3) Note Note PCM5 PCM4 PCM3 PCM2 PCM1 PCM0 PCM2 and PCM3 pin output latch level selection High-level output PCMn (n = 0, 1, 4 , 5) pin output latch level selection Low-level output...
CHAPTER 4 SETTING REGISTERS Main Processing 4.8.1 Chattering countermeasure To eliminate chattering, a change in the switch (P03) status is determined by reading inputs every 10 ms and detecting the same level for the switch status two times in succession. Switch isn't pressed Switch is pressed Switch isn't pressed...
CHAPTER 4 SETTING REGISTERS 4.8.2 Main processing In the main processing in C language, the following operation is performed. In this sample program, the correspondence between the input and output data is set in an array. START Initialize variables Initialize p e rip h e ra l fu n ctio n s A cq u ire th e s w itc h sta tu s...
Page 39
CHAPTER 4 SETTING REGISTERS /**************************************************************************** Main processing *****************************************************************************/ void main( void ) extern unsigned int _S_romp; /* External reference of ROMization symbol /*----------------------------------------------*/ /* Variable declaration and initial variable setting */ /*----------------------------------------------*/ const unsigned char outdata[] = { /* Array for the LED display pattern data 0x0c, /* Turns off all LEDs.
Page 40
CHAPTER 4 SETTING REGISTERS /*------------------------------------*/ /* LED lighting processing /*------------------------------------*/ while ( 1 ) indata <<= 1; /* Updates the previous switch status value */ indata |= P0.3; /* Updates the current switch status value */ if ( ( indata & 0b00001111 ) == 0b00001100 ) count++;...
APPENDIX A PROGRAM LIST The V850ES/Jx3 microcontroller source program is shown below as a program list example. ● minicube2.s #------------------------------------------------------------------------------ NEC Electronics V850ES/Jx3 series #------------------------------------------------------------------------------ V850ES/JJ3 JG3 sample program #------------------------------------------------------------------------------ LED lighting switch control #------------------------------------------------------------------------------ #[History] 2009.6.-- Released #------------------------------------------------------------------------------ #[Overview] This sample program secures the resources required when using MINICUBE2.
Page 43
APPENDIX A PROGRAM LIST ● AppNote_LED.dir Sample link directive file (not use RTOS/use internal memory only) Copyright (C) NEC Electronics Corporation 2002 All rights reserved by NEC Electronics Corporation. This is a sample file. NEC Electronics assumes no responsibility for any losses incurred by customers or third parties arising from the use of this file.
Page 45
APPENDIX A PROGRAM LIST ● main.c /*------------------------------------------------------------------------------*/ NEC Electronics V850ES/Jx3 series /*------------------------------------------------------------------------------*/ V850ES/JJ3 sample program /*------------------------------------------------------------------------------*/ LED lighting switch control /*------------------------------------------------------------------------------*/ /*[History] 2009.06.-- Released /*------------------------------------------------------------------------------*/ /*[Overview] This sample program selects the clock frequency, sets the port I/Os, and performs the basic initial settings of the V850ES/JJ3 microcontroller. The main processing operation performed after the completion of the initial settings controls the lighting of two LEDs by using one switch input.
Page 46
APPENDIX A PROGRAM LIST /* <Switch input and LED lighting> /* │---------------―-----------------------------―----------+ /* │Number of times the switch is pressed │ LED1 │ LED2 │ /* │ │ (PCM3) │ (PCM2) │ (P03) /* │――――---------―-------------------- │-------- │-------- │ /* │ │...
Page 48
APPENDIX A PROGRAM LIST /*--------------------------------------------------------*/ /* Setting the internal oscillation mode register (RCM) */ /*--------------------------------------------------------*/ static void f_init_rcm( void ) RSTOP = 1; /* Stops the internal oscillator. return; /*------------------------------------*/ /* Setting watchdog timer 2 (WDTM2) */ /*------------------------------------*/ static void f_init_wdtm2( void ) WDTM2 = 0b00000000;...
Page 49
APPENDIX A PROGRAM LIST while( LOCK ); /* Wait for PLL stabled */ SELPLL = 1; /* Set PLL mode */ /* Setting the PCC register */ /* Sets to not divide the clock. */ #pragma asm push r10 mov 0x80, r10 st.b r10, PRCMD st.b r10, PCC pop r10...
Page 50
APPENDIX A PROGRAM LIST P5 = 0b00000000; /* Sets P50 to P55 to low-level output. PM5 = 0b11000000; = 0b00000000; /* Sets P68 to P615 to low-level output. */ PM6H = 0b00000000; = 0b00000000; /* Sets P60 to P67 to low-level output. */ PM6L = 0b00000000;...
Page 51
APPENDIX A PROGRAM LIST PCM = 0b00000000; /* Sets PCM0 and PCM5 to low-level output. PMCM = 0b11000000; In the V850ES/ JG3, sets only PCM0 to PCM3. PCM = 0b00000000; /* Sets PCM0 and PCM3 to low-level output. PMCM = 0b11110000; PCS = 0b00000000;...
Page 52
APPENDIX A PROGRAM LIST /*---------------------------------------------------*/ /* Setting the switch input and LED control ports */ /*---------------------------------------------------* /static void f_init_use_port( void ) /* Setting the switch output port */ P0 = 0b00000000; /* Sets P03 as an input. PM0 = 0b10001000; /* Setting the LED output port */ PCM = 0b00001100;...
Page 53
APPENDIX A PROGRAM LIST /*----------------------------------------*/ /* Peripheral-function initialization /*----------------------------------------*/ f_init_vswc(); /* Sets the VSWC register f_init_ocdm(); /* Sets on-chip debug mode register to normal operation mode f_init_rcm(); /* Disables the internal oscillator f_init_wdtm2(); /* Sets watchdog timer 2 f_init_lock(); /* Sets the CPU operation clock to PLL mode f_init_blank_port();...
Page 54
APPENDIX A PROGRAM LIST return; Application Note U19837EJ1V0AN...
Page 55
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/ [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.
Need help?
Do you have a question about the V850ES/J 3 Series and is the answer not in the manual?
Questions and answers