当前位置:首页 » 《随便一记》 » 正文

AB32VG1 按键控制LED_我是郑伟的博客

19 人参与  2022年05月11日 09:10  分类 : 《随便一记》  评论

点击全文阅读


使用AB32VG1在RT-Thread Studio 进行编写。

#include <rtthread.h>
#include "board.h"
int main(void)
{
    uint8_t green = rt_pin_get("PE.4");             //定义绿色LED灯的引脚,uint8_t为数据类型
    uint8_t key = rt_pin_get("PF.1");               //定义按键引脚
    rt_pin_mode(green, PIN_MODE_OUTPUT);            //定义LED为输出
    rt_pin_mode(key, PIN_MODE_INPUT_PULLUP );       //定义按键为输入
    rt_pin_write(green, PIN_HIGH);                  //将LED置为高电平
    while(1){
    if(rt_pin_read(key) == 1)
    {
        rt_pin_write(green, PIN_LOW);
    }
       if(rt_pin_read(key) == 0)
       {
        rt_pin_write(green, PIN_HIGH);
       }//while循环要有,使程序一直运行
    }
}

点击全文阅读


本文链接:http://zhangshiyu.com/post/39889.html

定义  按键  引脚  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1