当前位置:网站首页>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)
完整工程
边栏推荐
- My C language learning record (blue bridge) -- under the pointer
- Inherit day01
- Custom attribute access__ getattribute__/ Settings__ setattr__/ Delete__ delattr__ method
- Deep parsing pointer and array written test questions
- 1003 emergency (25 points), "DIJ deformation"
- What are the principles of software design (OCP)
- Overview of OCR character recognition methods
- ArabellaCPC 2019(补题)
- 11. Container with the most water
- Image super-resolution using deep convolutional networks(SRCNN)解读与实现
猜你喜欢
Problems encountered in 2022 work IV
ASU & OSU | model based regularized off-line meta reinforcement learning
2022工作中遇到的问题四
SAP ALV单元格级别设置颜色
[pointer training - eight questions]
【RISC-V】外部中断
Force buckle 1189 Maximum number of "balloons"
Microsoft Research, UIUC & Google research | antagonistic training actor critic based on offline training reinforcement learning
Python implementation of maddpg - (1) openai maddpg environment configuration
NR modulation 1
随机推荐
Polymorphic day02
canvas切积木小游戏代码
Restful style
继承day01
SD卡報錯“error -110 whilst initialising SD card
Teach you to build your own simple BP neural network with pytoch (take iris data set as an example)
[risc-v] external interrupt
下一个行业风口:NFT 数字藏品,是机遇还是泡沫?
Daily question brushing plan-2-13 fingertip life
Huawei, H3C, Cisco command comparison, mind map form from the basic, switching, routing three directions [transferred from wechat official account network technology alliance station]
Web security SQL injection vulnerability (1)
3.2 rtthread 串口设备(V2)详解
February 14, 2022 Daily: Google long article summarizes the experience of building four generations of TPU
Problems encountered in 2022 work IV
Jenkins basic knowledge ----- detailed explanation of 03pipeline code
1.16 - 校验码
How to choose PLC and MCU?
遥感图像超分辨率论文推荐
Differences and application scenarios between resulttype and resultmap
Research on cooperative control of industrial robots