当前位置:网站首页>2.2 STM32 GPIO操作
2.2 STM32 GPIO操作
2022-07-06 03:24: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)
完整工程
边栏推荐
- SD卡报错“error -110 whilst initialising SD card
- mysqldump数据备份
- SAP ALV颜色代码对应颜色(整理)
- codeforces每日5題(均1700)-第六天
- These are not very good
- Linear regression and logistic regression
- Jenkins basic knowledge ----- detailed explanation of 03pipeline code
- Distributed service framework dobbo
- February 14, 2022 Daily: Google long article summarizes the experience of building four generations of TPU
- Custom attribute access__ getattribute__/ Settings__ setattr__/ Delete__ delattr__ method
猜你喜欢

Mysqldump data backup

Web security SQL injection vulnerability (1)

Codeforces 5 questions par jour (1700 chacune) - jour 6

Codeworks 5 questions per day (1700 average) - day 6

Eight super classic pointer interview questions (3000 words in detail)

StrError & PERROR use yyds dry inventory

11. Container with the most water

深入探究指针及指针类型

Performance analysis of user login TPS low and CPU full

three.js网页背景动画液态js特效
随机推荐
深度解析指针与数组笔试题
Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
[padding] an error is reported in the prediction after loading the model weight attributeerror: 'model' object has no attribute '_ place‘
Getting started with applet cloud development - getting user search content
遥感图像超分辨率论文推荐
Image super-resolution using deep convolutional networks(SRCNN)解读与实现
OCR文字识别方法综述
如何做好功能测试
JS regular filtering and adding image prefixes in rich text
Item 10: Prefer scoped enums to unscoped enums.
深入探究指针及指针类型
【RISC-V】外部中断
jsscript
Four logs of MySQL server layer
JS音乐在线播放插件vsPlayAudio.js
Redo file corruption repair
2、GPIO相关操作
真机无法访问虚拟机的靶场,真机无法ping通虚拟机
ERA5再分析资料下载攻略
继承day01