먼저 블럭다이어그램을 통해서 타이머 종류를 살펴봅니다.
16bit타이머인 TAU0 - 4채널, 와치독 타이머, 12bit interval timer가 보입니다.
기본타이머인 16bit 타이머 TAU0 0채널을 사용하여 millis()함수를 만들어 보겠습니다.
프로젝트를 생성 후 Code Generator란에서 Timer를 선택하면 다음과 같은 메뉴가 나옵니다.
타이머 모드가 몇가지 존재하는데 간단하게 채널 0번을 Interval timer로 설정 하였습니다.
1ms Interval value를 설정합니다.
타이머 인터럽트를 사용할 것이므로 하단의 Generates INTTM00을 체크합니다.
Reflect in PIN 및 Generates Code를 클릭하면 다음과 같이 파일이 생성됩니다.
저의 경우 Watchdog을 unused 했으므로 wdt 파일은 생성되지 않았습니다. (Default는 생성됨)
r_cg_timer_user 함수는 인터럽트가 발생하는 Vector가 있는 함수입니다.
/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2011, 2021 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/
/***********************************************************************************************************************
* File Name : r_cg_timer_user.c
* Version : CodeGenerator for RL78/G12 V2.04.06.02 [08 Nov 2021]
* Device(s) : R5F1026A
* Tool-Chain : CA78K0R
* Description : This file implements device driver for TAU module.
* Creation Date: 22-05-16 ¿ù
***********************************************************************************************************************/
/***********************************************************************************************************************
Pragma directive
***********************************************************************************************************************/
#pragma interrupt INTTM00 r_tau0_channel0_interrupt
/* Start user code for pragma. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
Includes
***********************************************************************************************************************/
#include "r_cg_macrodriver.h"
#include "r_cg_timer.h"
/* Start user code for include. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"
/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
/* Start user code for global. Do not edit comment generated here */
uint32_t millis(void);
volatile uint32_t ms_cnt = 0;
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
* Function Name: r_tau0_channel0_interrupt
* Description : This function is INTTM00 interrupt service routine.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
__interrupt static void r_tau0_channel0_interrupt(void)
{
/* Start user code. Do not edit comment generated here */
ms_cnt++;
/* End user code. Do not edit comment generated here */
}
/* Start user code for adding. Do not edit comment generated here */
uint32_t millis(void)
{
uint32_t ret;
DI();
ret = ms_cnt;
EI();
return ret;
}
/* End user code. Do not edit comment generated here */
millis()함수를 추가했습니다.
main()함수에서는 구동하는 구문을 추가하였습니다.
/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2011, 2021 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/
/***********************************************************************************************************************
* File Name : r_main.c
* Version : CodeGenerator for RL78/G12 V2.04.06.02 [08 Nov 2021]
* Device(s) : R5F1026A
* Tool-Chain : CA78K0R
* Description : This file implements main function.
* Creation Date: 22-05-16 ¿ù
***********************************************************************************************************************/
/***********************************************************************************************************************
Pragma directive
***********************************************************************************************************************/
/* Start user code for pragma. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
Includes
***********************************************************************************************************************/
#include "r_cg_macrodriver.h"
#include "r_cg_cgc.h"
#include "r_cg_port.h"
#include "r_cg_timer.h"
/* Start user code for include. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"
/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
/* Start user code for global. Do not edit comment generated here */
extern uint32_t millis(void);
uint8_t led_flag = 0;
uint32_t pre_time = 0;
/* End user code. Do not edit comment generated here */
void R_MAIN_UserInit(void);
/***********************************************************************************************************************
* Function Name: main
* Description : This function implements main function.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void main(void)
{
R_MAIN_UserInit();
/* Start user code. Do not edit comment generated here */
pre_time = millis();
while (1U)
{
if(millis() - pre_time >= 500)
{
pre_time = millis();
if(led_flag == 0) led_flag = 1;
else led_flag = 0;
}
if(led_flag)
{
P1 = _00_Pn3_OUTPUT_0 | _00_Pn4_OUTPUT_0;
}
else
{
P1 = _08_Pn3_OUTPUT_1;
}
}
/* End user code. Do not edit comment generated here */
}
/***********************************************************************************************************************
* Function Name: R_MAIN_UserInit
* Description : This function adds user code before implementing main function.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_MAIN_UserInit(void)
{
/* Start user code. Do not edit comment generated here */
hdwinit();
EI();
R_TAU0_Channel0_Start();
/* End user code. Do not edit comment generated here */
}
/* Start user code for adding. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
500ms로 정상 작동되는게 확인됩니다.
반응형
'b. 임베디드 > R5F1026A-TB' 카테고리의 다른 글
[R5F1026A-TB] Input 테스트 (4) | 2022.05.18 |
---|---|
[R5F1026A-TB] 사용할 모듈 및 환경 설정 살펴보기 (0) | 2022.05.16 |