当前位置:网站首页>什么是GPIO,它有什么用
什么是GPIO,它有什么用
2022-07-26 15:43:00 【谭广健】
很早就想写这篇文章了,因为不少小伙伴和同学对开发STM32中的GPIO_WriteBit、GPIO_SetBits、GPIO_ResetBits 是什么都搞不懂。。每次都要花时间跟他们扫盲。。好吧,这次就一次扫清。
首先:GPIO(或GPIO口)就是通用输入/输出端口,通俗地说,就是一些CPU的引脚,可以通过它们输出高低电平或者通过它们读入引脚的状态-是高电平或是低电平;就是0:1输入和输出。
而其中常用就有:
GPIO_WriteBit:这个字面意思就是指定引脚的设置和清除。
GPIO_SetBits:就是设置指定引脚的数据端口。
GPIO_ResetBits:清除指定引脚的数据端口。
那怎么用呢?首先必须初始一下GPIO,就是告诉系统我要用这个引脚,那怎么表达,请看下面
void GPIO_INIT(void){
GPIO_InitTypeDef GPIO_InitStructure; //声明结构体,名字是GPIO_InitStructure,结构体原型由GPIO_InitTypeDef
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);//调用该函数使能GPIOB时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 |GPIO_Pin_5;//初始化引脚
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//速度 50MHz
GPIO_Init(GPIOE,&GPIO_InitStructure);//配置GPIO
}这样就初始化,我们需要的引脚;然后我只需要对引脚传出底电平还是高电平,因为这样就可以控制引脚是否闭合。
GPIO_WriteBit(GPIOE, GPIO_Pin_4,0); 或 GPIO_ResetBits(GPIOE,GPIO_Pin_4); //拉入底电平 GPIO_WriteBit(GPIOE, GPIO_Pin_4,1); 或 GPIO_SetBits(GPIOE,GPIO_Pin_4); //拉入高电平边栏推荐
- University rankings in Beijing
- 2022你的安全感是什么?沃尔沃年中问道
- No module named ‘win32gui‘
- 2021年软件测试工具趋势
- PS + PL heterogeneous multicore case development manual for Ti C6000 tms320c6678 DSP + zynq-7045 (4)
- [leetcode] 33. Search rotation sort array
- .net get injection object manually
- Zynq PS + PL heterogeneous multicore Case Development Manual of Ti C6000 tms320c6678 DSP + zynq-7045 (1)
- parker泵PV140R1K1T1PMMC
- 如何将规划图转成带经纬度的矢量数据geojson
猜你喜欢

OSPF综合实验

German EMG electric actuator eb800-60ii

阿里巴巴一面 :十道经典面试题解析

Tool skill learning (II): pre skills shell

Refuse noise, the entry journey of earphone Xiaobai

Glyphicons V3 字体图标查询

Google Earth Engine——MERRA-2 M2T1NXAER:1980-2022年气溶胶逐日数据集

【EXPDP导出数据】expdp导出23行记录,且不包含lob字段的表,居然用时48分钟,请大家帮忙看看

Gcc/g++ and dynamic and static libraries and GDB

# 工欲善其事必先利其器-C语言拓展--嵌入式C语言(十一)
随机推荐
Understanding weight sharing in convolutional neural networks
PS + PL heterogeneous multicore case development manual for Ti C6000 tms320c6678 DSP + zynq-7045 (3)
TI C6000 TMS320C6678 DSP+ Zynq-7045的PS + PL异构多核案例开发手册(4)
PS + PL heterogeneous multicore case development manual for Ti C6000 tms320c6678 DSP + zynq-7045 (4)
Implementation of personalized healthy diet recommendation system based on SSM
数仓:爱奇艺数仓平台建设实践
bucher齿轮泵QX81-400R301
How to convert planning map into vector data with longitude and latitude geojson
Sklearn clustering clustering
2021年软件测试工具趋势
This article explains in detail the discovery and processing of bigkey and hotkey in redis
SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
My brother created his own AI anti procrastination system, and he was "blinded" when playing with his mobile phone | reddit was hot
Google Earth Engine——MERRA-2 M2T1NXAER:1980-2022年气溶胶逐日数据集
工具技能学习(二):前置技能-shell
Digital warehouse: iqiyi digital warehouse platform construction practice
理解卷积神经网络中的权值共享
开发日常小结(11):文件上传功能改进:中文字符检测与文本内容处理
基于SSM开发实现校园疫情防控管理系统
拒绝噪声,耳机小白的入门之旅