当前位置:网站首页>什么是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); //拉入高电平边栏推荐
- sklearn clustering聚类
- 超简单!只需简单几步即可为TA定制天气小助理!!
- Understanding weight sharing in convolutional neural networks
- 邻接矩阵的COO格式
- QT is the most basic layout, creating a window interface
- ROS problems and Solutions - relying on package installation and unable to correct errors
- Using two stacks to implement a queue
- Data warehouse: Data Modeling and log system in data warehouse construction
- Coo format of adjacency matrix
- 我们被一个 kong 的性能 bug 折腾了一个通宵
猜你喜欢

VS2019Debug模式太卡进不去断点

# 工欲善其事必先利其器-C语言拓展--嵌入式C语言(十一)

小哥自创AI防拖延系统,一玩手机就被“闪瞎” | Reddit高热

认识JS基础与浏览器引擎

Understand │ XSS attack, SQL injection, CSRF attack, DDoS attack, DNS hijacking

【DSCTF2022】pwn补题记录

Musk was exposed to be the founder of Google: he broke up his best friend's second marriage and knelt down to beg for forgiveness

Quanzhi a40i industrial core board, 100% domestic 4-core arm cortex-a7, supports "dual screen abnormal display" [display interface capability, preferred scheme for industrial HMI]

关于我写的IDEA插件能一键生成service,mapper....这件事(附源码)

一文搞懂│XSS攻击、SQL注入、CSRF攻击、DDOS攻击、DNS劫持
随机推荐
Bucher gear pump qx81-400r301
API 版本控制【 Eolink 翻译】
Daily1:SVM
zabbix 6.2.0部署
撤回就看不到了?三步让你微信防撤回。
ES6 advanced - query commodity cases
2022 what is your sense of security? Volvo asked in the middle of the year
大型仿人机器人整机构型研究与应用
Creation and traversal of binary tree
Can't you see the withdrawal? Three steps to prevent withdrawal on wechat.
German EMG e-anji thruster ed301/6 HS
一款可视化浏览器历史的 Firefox/Chrome 插件
Chapter 7 supporting CORS in rest services
什么是虚拟摄像头
.NET 手动获取注入对象
[expdp export data] expdp exports a table with 23 rows of records and no lob field. It takes 48 minutes. Please help us have a look
Basic specification of component development, localstorage and sessionstorage, object data to basic value, prototype chain use
中金财富证券安全吗 开户要多久
Refuse noise, the entry journey of earphone Xiaobai
13 years of senior developers share a year of learning rust experience: from the necessary bibliography to code practice