单片机先从跑马灯走起,由于前面已经使用过FreeRTOS,直接才有FreeRTOS+LED灯控制作为第一篇开发板体验。
从图中可以看出,LED4可以作为系统是否上电的指示,其他三个LED可以作为控制来演示,低电平亮,高电平不亮。
文件->新建->瑞萨c/c++项目->Renesas RA->c/c++->下一步->输入项目名称->下一步->Device选择R7FA6M5BH3CFC->下一步->下一步->RTOS选择FreeRTOS->下一步->完成
项目资源管理器->configuration.xml->Pins->P4->P400->Symbolic Name: LED0,Mode: Output mode(Initial High) 其他两个LED类似操作->Statcks->New Thread->Symbol: led_thread,Name: LED_Thread->Generate Project Content.
在Src/led_thread_entry.c编辑代码
#include "led_thread.h"
/* LED_Thread entry function */
/* pvParameters contains TaskHandle_t */
void led_thread_entry(void *pvParameters)
{
FSP_PARAMETER_NOT_USED (pvParameters);
/* TODO: add your own code here */
R_IOPORT_Open(&g_ioport_ctrl, g_ioport.p_cfg);
while (1)
{
vTaskDelay (1000);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_00, BSP_IO_LEVEL_LOW);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_03, BSP_IO_LEVEL_HIGH);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_04, BSP_IO_LEVEL_HIGH);
vTaskDelay (1000);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_00, BSP_IO_LEVEL_HIGH);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_03, BSP_IO_LEVEL_LOW);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_04, BSP_IO_LEVEL_HIGH);
vTaskDelay (1000);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_00, BSP_IO_LEVEL_HIGH);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_03, BSP_IO_LEVEL_HIGH);
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_04, BSP_IO_LEVEL_LOW);
}
}
更多回帖