当前位置:网站首页>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
边栏推荐
- Deno介绍
- 2.1 rtthread pin设备详解
- Mysqldump data backup
- SAP ALV单元格级别设置颜色
- Pelosi: Congress will soon have legislation against members' stock speculation
- February 14, 2022 Daily: Google long article summarizes the experience of building four generations of TPU
- SD card reports an error "error -110 whilst initializing SD card
- Image super-resolution using deep convolutional networks(SRCNN)解读与实现
- Analyze 菜单分析
- Brush questions in summer -day3
猜你喜欢

Analyze menu analysis

3.1 rtthread 串口设备(V1)详解

IPv6 jobs

Map sorts according to the key value (ascending plus descending)

Research on cooperative control of industrial robots

Quartz misfire missed and compensated execution

Recommended foreign websites for programmers to learn

2、GPIO相关操作

Esbuild & SWC: a new generation of construction tools

Record the process of reverse task manager
随机推荐
Leetcode problem solving -- 108 Convert an ordered array into a binary search tree
How to choose PLC and MCU?
Web security SQL injection vulnerability (1)
Shell 传递参数
给新人工程师组员的建议
Selenium share
Idea push rejected solution
Pointer written test questions ~ approaching Dachang
Problems encountered in 2022 work IV
Pytorch load data
Redis cache breakdown, cache penetration, cache avalanche
【SLAM】ORB-SLAM3解析——跟踪Track()(3)
Mysqldump data backup
Cross origin cross domain request
Analyze menu analysis
Distributed service framework dobbo
3857 Mercator coordinate system converted to 4326 (WGS84) longitude and latitude coordinates
Game theory matlab
NR modulation 1
继承day01