【Follow me第二季第3期】入门任务:Blink,按键
本帖最后由 Juggernaut 于 2024-11-28 08:44 编辑<p>先把工程建立起来,FSP很方便,选择好芯片型号:</p>
<div style="text-align: center;"></div>
<p> </p>
<p><span style="font-size:18px;"><strong>Blink配置</strong></span></p>
<div style="text-align: center;"></div>
<p>根据EK-RA6M5的PCB,P006,P007,P008分别对应LED1,LED2,LED3,逐一配置好,此处为输出模式,本案例LED1/LED2用于blink,LED3用于响应案件事件。</p>
<div style="text-align: center;"></div>
<p>代码为</p>
<pre>
<code> R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_06, BSP_IO_LEVEL_HIGH); //LED1亮
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_07, BSP_IO_LEVEL_HIGH); //LED2亮
R_BSP_SoftwareDelay(500, BSP_DELAY_UNITS_MILLISECONDS); //延时500ms
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_06, BSP_IO_LEVEL_LOW); //LED1灭亮
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_07, BSP_IO_LEVEL_LOW); //LED2灭亮
R_BSP_SoftwareDelay(500, BSP_DELAY_UNITS_MILLISECONDS); //延时500ms</code></pre>
<p><span style="font-size:18px;"><strong>按键功能</strong></span></p>
<p>按键选择按钮2,对应的pin为P005:</p>
<div style="text-align: center;"></div>
<p>同样配置好,此处为输入模式:</p>
<div style="text-align: center;"></div>
<p>代码为:</p>
<pre>
<code> R_IOPORT_PinRead(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_05, &key_state);
if(key_state==BSP_IO_LEVEL_LOW){
//软件消抖
R_BSP_SoftwareDelay(10, BSP_DELAY_UNITS_MILLISECONDS);
//点亮LED3
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_08, BSP_IO_LEVEL_HIGH); //LED3亮
//等待按键松开
while(key_state==BSP_IO_LEVEL_LOW)
{
R_IOPORT_PinRead(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_05, &key_state);
}
//熄灭LED3
R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_08, BSP_IO_LEVEL_LOW); //LED3灭
}</code></pre>
<p><strong><span style="font-size:18px;">运行测试</span></strong></p>
<p>配置好后,点击生成代码按钮,FSP很方便的生成配置和代码。</p>
<p>编辑好:</p>
<pre>
<code>Extracting support files...
08:40:33 **** 项目blink配置Release的增量构建 ****
make -r -j8 all
arm-none-eabi-size --format=berkeley "blink.elf"
text data bss dec hex filename
4284 8 2580 6872 1ad8 blink.elf
08:40:34 Build Finished. 0 errors, 0 warnings. (took 157ms)
</code></pre>
<p>下载至EK-RA65板子:</p>
<p>可以看出LED1 LED2都在blink了,LED3根据按键2的动作响应。</p>
<p>334a9aaf90a69a9b394459e091bd4b23<br />
</p>
<p>至此,BLINK和按键任务完成!</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
页:
[1]