当前位置:网站首页>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
边栏推荐
- Redo file corruption repair
- Introduction to DeNO
- 【paddle】加载模型权重后预测报错AttributeError: ‘Model‘ object has no attribute ‘_place‘
- Custom attribute access__ getattribute__/ Settings__ setattr__/ Delete__ delattr__ method
- An article about liquid template engine
- Image super-resolution using deep convolutional networks(SRCNN)解读与实现
- Restful style
- Linear programming matlab
- three. JS page background animation liquid JS special effect
- 记录一下逆向任务管理器的过程
猜你喜欢
Mysqldump data backup
ASU & OSU | model based regularized off-line meta reinforcement learning
Web security SQL injection vulnerability (1)
Explore pointers and pointer types in depth
OCR文字识别方法综述
canvas切积木小游戏代码
教你用Pytorch搭建一个自己的简单的BP神经网络( 以iris数据集为例 )
Force buckle 1189 Maximum number of "balloons"
Performance analysis of user login TPS low and CPU full
指针笔试题~走近大厂
随机推荐
Eight super classic pointer interview questions (3000 words in detail)
StrError & PERROR use yyds dry inventory
jsscript
3.1 rtthread 串口设备(V1)详解
Restful style
Analyze 菜单分析
教你用Pytorch搭建一个自己的简单的BP神经网络( 以iris数据集为例 )
记录一下逆向任务管理器的过程
Four logs of MySQL server layer
Derivation of anti Park transform and anti Clarke transform formulas for motor control
如何做好功能测试
SD卡报错“error -110 whilst initialising SD card
IPv6 comprehensive experiment
MPLS experiment
Polymorphic day02
深入刨析的指针(题解)
深度解析指针与数组笔试题
The real machine cannot access the shooting range of the virtual machine, and the real machine cannot Ping the virtual machine
2.2 STM32 GPIO操作
Mysql database operation