当前位置:网站首页>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)
完整工程
边栏推荐
- Some problem records of AGP gradle
- SAP ALV颜色代码对应颜色(整理)
- Quartz misfire missed and compensated execution
- Polymorphic day02
- ArabellaCPC 2019(补题)
- Codeworks 5 questions per day (1700 average) - day 6
- Princeton University, Peking University & UIUC | offline reinforcement learning with realizability and single strategy concentration
- Microsoft Research, UIUC & Google research | antagonistic training actor critic based on offline training reinforcement learning
- Redis SDS principle
- EDCircles: A real-time circle detector with a false detection control 翻译
猜你喜欢

three.js网页背景动画液态js特效

电机控制反Park变换和反Clarke变换公式推导

Python implementation of maddpg - (1) openai maddpg environment configuration

MPLS experiment

Who is the winner of PTA

Computer graduation project asp Net fitness management system VS development SQLSERVER database web structure c programming computer web page source code project

施努卡:视觉定位系统 视觉定位系统的工作原理

Recommended foreign websites for programmers to learn

Web security SQL injection vulnerability (1)

深入刨析的指针(题解)
随机推荐
BUUCTF刷题笔记——[极客大挑战 2019]EasySQL 1
jsscript
11. Container with the most water
1003 emergency (25 points), "DIJ deformation"
SD卡报错“error -110 whilst initialising SD card
SD卡報錯“error -110 whilst initialising SD card
遥感图像超分辨率论文推荐
The next industry outlet: NFT digital collection, is it an opportunity or a foam?
施努卡:视觉定位系统 视觉定位系统的工作原理
[padding] an error is reported in the prediction after loading the model weight attributeerror: 'model' object has no attribute '_ place‘
An article about liquid template engine
[Li Kou] the second set of the 280 Li Kou weekly match
Precautions for single chip microcomputer anti reverse connection circuit
Performance test method of bank core business system
暑期刷题-Day3
Jenkins basic knowledge ----- detailed explanation of 03pipeline code
Erreur de la carte SD "erreur - 110 whilst initialisation de la carte SD
【概念】Web 基础概念认知
pytorch加载数据
Research on cooperative control of industrial robots