实验功能:500ms的延时的延时电量LED
打开RASC 配置软件
添加一个STACKS
配置
#ifndef __BSP_TIM0_H__
#define __BSP_TIM0_H__
#include "hal_data.h"
#include "stdio.h"
void bsp_timer_init(void);
#endif
#include "bsp_tim0.h"
/* 定时器的初始化 */
void bsp_timer_init(void)
{
fsp_err_t err;
/* 配置定时器 */
err = R_AGT_Open(&g_timer0_ctrl, &g_timer0_cfg);
assert(FSP_SUCCESS == err);
err = R_AGT_Start (&g_timer0_ctrl);
//使能定时器
assert(FSP_SUCCESS == err);
}
/* 定时器的中断回调 */
void timer0_callback(timer_callback_args_t *p_args)
{
static uint32_t led_s=0;
if (TIMER_EVENT_CYCLE_END == p_args->event)
{
led_s = !led_s;
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_15, led_s);
}
}
void hal_entry(void)
{
/* TODO: add your own code here */
//初始化LED io
R_IOPORT_Open (&g_ioport_ctrl, g_ioport.p_cfg);
//串口初始化
bsp_uart_init();
//定时器初始化
bsp_timer_init();
printf("hello RA4\r\n");
//
while(1)
{
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_04, BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS); //延时 100毫秒
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_04, BSP_IO_LEVEL_HIGH);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_05, BSP_IO_LEVEL_LOW);
R_BSP_SoftwareDelay(100, BSP_DELAY_UNITS_MILLISECONDS); //延时 100毫秒
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_05, BSP_IO_LEVEL_HIGH);
}
#if BSP_TZ_SECURE_BUILD
/* Enter non-secure code */
R_BSP_NonSecureEnter();
#endif
}
更多回帖