当前位置:网站首页>2.2 STM32 GPIO operation
2.2 STM32 GPIO operation
2022-07-06 03:24:00 【rou252051452】
1、 summary
By program PIN Device input , Output , Interruption, etc .
2、 Input
3、 Output

4、 interrupt

4、 Test functions
/**
1、 Output :
1) Use the button of Polaris on the punctual atomic development board LED0(PB1) and LED1(PB0) As the output IO test .
2) After the button is pressed ,LED0 bright
3) After the button is released ,LED0 destroy
2、 Input :
1) Use the button of Polaris on the punctual atomic development board KEY0(PH3) Test as input
2) After the button is pressed ,LED0 bright
3) After the button is released ,LED0 destroy
3、 interrupt :
1) Use the button of Polaris on the punctual atomic development board KEY1(PH2) As interrupt input
2) After the button is pressed ,LED1 bright
3) After the button is released ,LED1 destroy
**/
#include "rtthread.h"
#include "board.h"
// The macro definition obtains the pin number .
#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()
{
// adopt API Get pin number
KEY0 = rt_pin_get("PH.3");
KEY2 = rt_pin_get("PC.13");
// Set pin mode
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);
// test LED Lamp output
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);
}
// Interrupt callback function binding
rt_pin_attach_irq(KEY2, PIN_IRQ_MODE_RISING_FALLING, exti_callback, RT_NULL);
// Interrupt enable
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)
Complete the project
边栏推荐
- Lua uses require to load the shared library successfully, but the return is Boolean (always true)
- 银行核心业务系统性能测试方法
- SAP ALV颜色代码对应颜色(整理)
- 记录一下逆向任务管理器的过程
- 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
- Pointer written test questions ~ approaching Dachang
- 2.2 STM32 GPIO操作
- 给新人工程师组员的建议
- Esbuild & SWC: a new generation of construction tools
- mysqldump数据备份
猜你喜欢

C language judgment, ternary operation and switch statement usage

Selenium share

Tidb ecological tools (backup, migration, import / export) collation

Pytorch load data

canvas切积木小游戏代码

【RISC-V】外部中断

Game theory matlab

Pytorch基础——(1)张量(tensor)的初始化
![[slam] orb-slam3 parsing - track () (3)](/img/87/b580837778c2c9f6bac5ba49403d6b.png)
[slam] orb-slam3 parsing - track () (3)
How to do function test well
随机推荐
ArabellaCPC 2019(补题)
Getting started with applet cloud development - getting user search content
SAP ALV cell level set color
Map sorts according to the key value (ascending plus descending)
Eight super classic pointer interview questions (3000 words in detail)
SD卡报错“error -110 whilst initialising SD card
EDCircles: A real-time circle detector with a false detection control 翻译
Idea push rejected solution
Introduction to DeNO
【Rust 笔记】18-宏
Game theory matlab
Who is the winner of PTA
Linear regression and logistic regression
IPv6 jobs
Shell pass parameters
OCR文字识别方法综述
Item 10: Prefer scoped enums to unscoped enums.
3857 Mercator coordinate system converted to 4326 (WGS84) longitude and latitude coordinates
How to write compile scripts compatible with arm and x86 (Makefile, cmakelists.txt, shell script)
SD卡報錯“error -110 whilst initialising SD card