1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Renesas RAマイコンを使ってみよう(3)~スイッチを使ってみよう~

Posted at

RAマイコンを使ってみよう~Lチカ編~の続きです。

今回は、スイッチを使ってみましょう。

ピン設定を確認する

P205 がスイッチに繋がっています。
image.png
Configuration を見ると SW1 になっています。
image.png
Developer Assistance から R_IOPORT_PinRead を探しプログラムに貼り付けます。
image.png
R_IOPORT_PinRead(&g_ioport_ctrl, SW1, &SW1_status) とプログラムを修正します。
ただし value が規定されていません。
bsp_io_level_t SW1_status を追加します。
image.png
次に、 Status に応じてプログラムを構成します。
SW1Status に応じてLEDが点滅するようにします。
image.png
sw1 と入力すると補完で sw1_status が出てきます。
image.png
image.png

void hal_entry(void)
{
    /* TODO: add your own code here */
   while(1){
       bsp_io_level_t SW1_status;
        R_IOPORT_PinRead(&g_ioport_ctrl, SW1, &SW1_status);
               if(SW1_status){
                   R_IOPORT_PinWrite(&g_ioport_ctrl, LED1,BSP_IO_LEVEL_HIGH );
               }else{
                   R_IOPORT_PinWrite(&g_ioport_ctrl, LED1,BSP_IO_LEVEL_LOW );
               }
    R_BSP_SoftwareDelay(3, BSP_DELAY_UNITS_MILLISECONDS);
    }
}

LED2の追加

今回も LED2 を修正しました。
image.png

プログラム

void hal_entry(void)
{
    /* TODO: add your own code here */
   while(1){

       bsp_io_level_t SW1_status;
        R_IOPORT_PinRead(&g_ioport_ctrl, SW1, &SW1_status);
               if(SW1_status){
                   R_IOPORT_PinWrite(&g_ioport_ctrl, LED1,BSP_IO_LEVEL_HIGH );
                   R_IOPORT_PinWrite(&g_ioport_ctrl, LED2,BSP_IO_LEVEL_LOW );

               }else{
                   R_IOPORT_PinWrite(&g_ioport_ctrl, LED1,BSP_IO_LEVEL_LOW );
                   R_IOPORT_PinWrite(&g_ioport_ctrl, LED2,BSP_IO_LEVEL_HIGH );
               }
    R_BSP_SoftwareDelay(3, BSP_DELAY_UNITS_MILLISECONDS);
    }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?