Renesas MCU Program 1

Publisher:VelvetDreamerLatest update time:2016-05-17 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

SH-stick serial port emulator, the study of Renesas microcontroller, or the simplest program to start, LED on and off, button control, equivalent to C language Hello world! The program includes the following parts: system initialization (FRQCR); I/O initialization; LED initialization; main program

//#include "typedefine.h"
#ifdef __cplusplus
//#include                         // Remove the comment when you use ios                  
//_SINT ios_base::Init::init_cnt;       // Remove the comment when you use ios
#endif
#ifdef __cplusplus
extern "C" {
void abort(void);
#endif
void main(void);
#ifdef __cplusplus
}
#endif

#include "iodefine.h"
#include "machine.h"

VOID InitClock( );
VOID InitPort( );
VOID InitLED( );
VOID InitKey( );
VOID Delay();
VOID Flaled();
VOID main( ){

InitClock(); //Initialize the clock
InitPort(); //Initialize the port function
InitLED(); //Initialize the LED port
InitKey(); //Initialize the key interrupt (IRQ0)


while(1)
{
   if(INTC.IRQSR.BIT.IRQ0F==1) //Judge whether an IRQ0 falling edge interrupt occurs
   {
    INTC.IRQSR.BIT.IRQ0F=0; //If an interrupt occurs, clear the interrupt flag
    if(INTC.IRQSR.BIT.IRQ0F==0) //Read the interrupt flag again to ensure that the interrupt flag is cleared before taking the next step
    {
     Flaled();
    }}

/*/
VOID Flaled( )

   PE.DRL.WORD = 0x05FF; // 所有LED点亮
   Delay(3000);
   PE.DRL.WORD = 0xFA20; // 关所有LED
   Delay(3000);
}
//

VOID Delay(unsigned int z)
{
unsigned int i=0,j=0;
for(i=z;i>0;i--)
{
   for(j=1000;j>0;j--);
}

}

//
VOID InitClock(){
CPG.FRQCR.WORD = 0x16DB; //Use 48MHz as internal clock and 24MHz as MTU2 clock
}

/*

//
VOID InitPort(){
PFC.PACRL1.BIT.PA2MD = 3; //PA2 is used as IRQ0 input function.
PFC.PBCRL2.BIT.PB5MD = 1; //PB5 is used as IRQ3 input function.
PFC.PEIORL.BIT.B5 = 1; //PE5 is used as output port
}

//
VOID InitLED(){
// PE.DRL.WORD = 0x05FF; // LEDs are all on
PFC.PEIORL.WORD |= 0xFA00; // PE15,14,13,12,11,9 are used as general I/O ports
}

//
VOID InitKey(){
INTC.IRQCR.BIT.IRQ0S = 1; //Detect interrupt request on falling edge
INTC.IPRA.BIT._IRQ0 = 9; //Set interrupt priority of IRQ0
}

#ifdef __cplusplus
void abort(void)
{

}
#endif

#renesasMCU
Reference address:Renesas MCU Program 1

Previous article:Hardware construction and operation process of Renesas MCU serial port download simulation program
Next article:My Introduction to Renesas MCU

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号