当前位置:网站首页>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
边栏推荐
- Résumé des méthodes de reconnaissance des caractères ocr
- JS music online playback plug-in vsplayaudio js
- Differences and application scenarios between resulttype and resultmap
- mysqldump数据备份
- I sorted out a classic interview question for my job hopping friends
- Redis SDS principle
- Tidb ecological tools (backup, migration, import / export) collation
- 施努卡:什么是视觉定位系统 视觉系统如何定位
- 下一个行业风口:NFT 数字藏品,是机遇还是泡沫?
- Analyze menu analysis
猜你喜欢
随机推荐
resulttype和resultmap的区别和应用场景
C language judgment, ternary operation and switch statement usage
Linear programming matlab
Leetcode problem solving -- 108 Convert an ordered array into a binary search tree
SAP ALV单元格级别设置颜色
What are the principles of software design (OCP)
Arabellacpc 2019 (supplementary question)
js凡客banner轮播图js特效
Selenium share
Item 10: Prefer scoped enums to unscoped enums.
Analyze 菜单分析
OCR文字识别方法综述
[Li Kou] the second set of the 280 Li Kou weekly match
MySQL Server层四个日志
[rust notes] 18 macro
深入刨析的指针(题解)
记录一下逆向任务管理器的过程
遥感图像超分辨重建综述
Remote Sensing Image Super-resolution and Object Detection: Benchmark and State of the Art
Image super-resolution using deep convolutional networks(SRCNN)解读与实现