当前位置:网站首页>2.2 STM32 GPIO操作
2.2 STM32 GPIO操作
2022-07-06 03:20:00 【rou252051452】
1、概述
通过程序进行PIN设备的输入,输出,中断等的验证工作。
2、输入
3、输出
4、中断
4、测试函数
/**
1、输出:
1)使用正点原子开发板北极星的按钮LED0(PB1)和LED1(PB0)作为输出IO测试。
2)按钮按下后,LED0亮
3)按钮松开后,LED0灭
2、输入:
1)使用正点原子开发板北极星的按钮KEY0(PH3)作为输入进行检测
2)按钮按下后,LED0亮
3)按钮松开后,LED0灭
3、中断:
1)使用正点原子开发板北极星的按钮KEY1(PH2)作为中断输入
2)按钮按下后,LED1亮
3)按钮松开后,LED1灭
**/
#include "rtthread.h"
#include "board.h"
//宏定义进行管脚编号的获取。
#define LED0 GET_PIN(B,1)
#define LED1 GET_PIN(B,0)
static rt_uint32_t KEY0 = 0;
static rt_uint32_t KEY2 = 0;
void exti_callback()
{
if(rt_pin_read(KEY2) == PIN_LOW)
{
rt_pin_write(LED1, PIN_LOW);
}
else
{
rt_pin_write(LED1, PIN_HIGH);
}
}
void example_gpio()
{
//通过API获取管脚编号
KEY0 = rt_pin_get("PH.3");
KEY2 = rt_pin_get("PC.13");
//设置管脚模式
rt_pin_mode(LED0, PIN_MODE_OUTPUT);
rt_pin_mode(LED1, PIN_MODE_OUTPUT);
rt_pin_mode(KEY0, PIN_MODE_INPUT_PULLUP);
rt_pin_mode(KEY2, PIN_MODE_INPUT_PULLUP);
//测试LED灯输出
for(rt_int8_t i = 0; i<5 ; i++)
{
rt_pin_write(LED0, PIN_LOW);
rt_pin_write(LED1, PIN_LOW);
rt_thread_delay(500);
rt_pin_write(LED0, PIN_HIGH);
rt_pin_write(LED1, PIN_HIGH);
rt_thread_delay(500);
}
//中断回调函数绑定
rt_pin_attach_irq(KEY2, PIN_IRQ_MODE_RISING_FALLING, exti_callback, RT_NULL);
//中断使能
rt_pin_irq_enable(KEY2, PIN_IRQ_ENABLE);
while(1)
{
if(rt_pin_read(KEY0) == PIN_LOW)
{
rt_pin_write(LED0, PIN_LOW);
}
else
{
rt_pin_write(LED0, PIN_HIGH);
}
rt_thread_delay(200);
}
}
MSH_CMD_EXPORT(example_gpio, example_gpio)
完整工程
边栏推荐
- 11. Container with the most water
- [concept] Web basic concept cognition
- Derivation of anti Park transform and anti Clarke transform formulas for motor control
- JS音乐在线播放插件vsPlayAudio.js
- MADDPG的pythorch实现——(1)OpenAI MADDPG环境配置
- Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
- 3857墨卡托坐标系转换为4326 (WGS84)经纬度坐标
- 记录一下逆向任务管理器的过程
- MySQL learning notes-10-tablespace recycling
- SAP ALV单元格级别设置颜色
猜你喜欢
Tidb ecological tools (backup, migration, import / export) collation
codeforces每日5题(均1700)-第六天
svg拖动点裁剪图片js特效
八道超经典指针面试题(三千字详解)
SAP ALV颜色代码对应颜色(整理)
[Li Kou] the second set of the 280 Li Kou weekly match
Problems encountered in 2022 work IV
Image super-resolution using deep convolutional networks(SRCNN)解读与实现
Reverse repackaging of wechat applet
js 正则过滤和增加富文本中图片前缀
随机推荐
Exness foreign exchange: the governor of the Bank of Canada said that the interest rate hike would be more moderate, and the United States and Canada fell slightly to maintain range volatility
mysqldump数据备份
Résumé des méthodes de reconnaissance des caractères ocr
EDCircles: A real-time circle detector with a false detection control 翻译
施努卡:什么是视觉定位系统 视觉系统如何定位
NR modulation 1
11. Container with the most water
Map sorts according to the key value (ascending plus descending)
C # create self host webservice
[pointer training - eight questions]
Detailed use of dbutils # yyds dry goods inventory #
Mysqldump data backup
Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
施努卡:3d视觉检测应用行业 机器视觉3d检测
Crazy, thousands of netizens are exploding the company's salary
这些不太会
暑期刷题-Day3
Huawei, H3C, Cisco command comparison, mind map form from the basic, switching, routing three directions [transferred from wechat official account network technology alliance station]
Python implementation of maddpg - (1) openai maddpg environment configuration
Handwriting database client