当前位置:网站首页>Lecture 4 - explain GPIO_ Write function and related routines
Lecture 4 - explain GPIO_ Write function and related routines
2022-07-27 02:17:00 【Ruomu·】
Preface
I explained the beginnings before GPIO Several functions of , Here is another function , This function operates on all ports
GPIO_Write function , Compared with other functions explained in the previous article , The biggest feature is that it can assign values to multiple ports .
Let's look at the function definition first :
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)
{
/* Check the parameters */
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
GPIOx->ODR = PortVal;
}
The first parameter is the same as before , Because it operates on multiple ports , We use GPIOA Take all ports of as an example , First parameter or GPIOA, Focus on the second parameter , See parameter definition :
* @param PortVal: specifies the value to be written to the port output data register.
It means , Specify the value to be written to the port output data register .
With LED Take the running water lamp as an example , With this function, we can directly configure PA0-PA15 16 Ports
Go straight to the code :
#include "stm32f10x.h" // Device header
#include "Delay.h"
int main()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);// Use RCC Turn on GPIO The clock
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // Push pull output
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;// hold 16 All ports are configured as push-pull output
//GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 ;// Bitwise “ or ” Select multiple ports
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz ;
GPIO_Init(GPIOA,&GPIO_InitStructure);
// Up to the top ,GPIO Initialization complete
while(1)
{
GPIO_Write(GPIOA,~0X0001);// Because the low level is on , So bitwise inversion , The first one at this time LED Light others as off
//0000 0000 0000 0001 Corresponding PA0-PA15 16 Ports , Its lowest PA0
Delay_ms(500);
GPIO_Write(GPIOA,~0X0002);//0000 0000 0000 0010
Delay_ms(500);
GPIO_Write(GPIOA,~0X0004);//0000 0000 0000 0100
Delay_ms(500);
GPIO_Write(GPIOA,~0X0008);//0000 0000 0000 1000
Delay_ms(500);
GPIO_Write(GPIOA,~0X0010);//0000 0000 0001 0000
Delay_ms(500);
GPIO_Write(GPIOA,~0X0020);//0000 0000 0010 0000
Delay_ms(500);
GPIO_Write(GPIOA,~0X0040);//0000 0000 0100 0000
Delay_ms(500);
GPIO_Write(GPIOA,~0X0080);//0000 0000 1000 0000
Delay_ms(500);
}
}
It should be noted that , stay GPIO_Init Of middle structure Pin Change to all ports , That is to say GPIO_Pin_All .
In a dead cycle , The second parameter is represented by hexadecimal numbers , Because we choose LED Illuminates for low level , So we take the opposite position , The first one at this time LED Light others as off , The bitwise reverse operation turns on the... On each port in turn LED, Add delay to realize LED Running water lamp .
边栏推荐
- Brief introduction of VLAN principle and specific experimental configuration
- OSPF protocol overview and basic concepts
- Flink1.13.6详细部署方式
- Gan's training skills: alchemist cultivation plan - generative confrontation network training, participation and improvement
- 最新C语言入门与进阶 -史上最全最详细的C语言教程!! 第一节-总览C语言概括
- RIP V2 的简单应用(v2的配置、宣告、手工汇总、RIPV2的认证、沉默接口、加快收敛)
- 7.8 锐捷网络笔试
- Static comprehensive experiment (comprehensive exercise of static route, loopback interface, default route, empty interface, floating static)
- Realize data interaction between two apps through fileprovider
- Electron FAQ 61 - must the client run with administrator privileges?
猜你喜欢
![C language implementation of the small game [sanziqi] Notes detailed logic clear, come and have a look!!](/img/b9/ade9a808a3f6d24cd9825dc9b010c1.png)
C language implementation of the small game [sanziqi] Notes detailed logic clear, come and have a look!!

Codeforces Round #809 (Div. 2), problem: (C) Qpwoeirut And The City

Codeforces Round #796 (Div. 2), problem: (1688C) Manipulating History

Is index reproduction text generation image is score quantitative experiment whole process reproduction inception score quantitative evaluation experiment step on the pit and avoid the pit process

Text to image paper intensive reading rat-gan: recursive affine transformation for text to image synthesis
![[MySQL] MySQL startup and shutdown commands and some error reports to solve problems](/img/23/b4c90604eba796692fbe049d2679d1.png)
[MySQL] MySQL startup and shutdown commands and some error reports to solve problems

静态路由基础配置(IP地址的规划、静态路由的配置),实现全网可达。

7.13 蔚来提前批笔试

超出隐藏显示省略号

【mysql】mysql启动关闭命令以及一些报错解决问题
随机推荐
Autojs learning - realize the display of date and lunar time
第四讲—讲解GPIO_Write函数以及相关例程
机械硬盘选购指南——从选购经历谈起
OSPF protocol overview and basic concepts
平面转换(位移、旋转、缩放)
静态路由缺省路由vlan实验
JS逻辑运算符
[详解C语言]一文带你玩转函数
[explain C language in detail] takes you to play with loop structure (for_while_do while)
6.29 众安暑期测开实习一面
测开基础 日常刷题 (持续更新ing...)
JS 99 multiplication table
7.8 Ruijie online written examination
OSPF configuration in mGRE environment and LSA optimization - reduce the amount of LSA updates (summary, special areas)
Autojs learning - realize image cutting
Codeforces Round #807 (Div. 2), problem: (C) Mark and His Unfinished Essay
OSPF在MGRE环境下的实验
The gradient descent method and Newton method are used to calculate the open radical
7.7 sheen Xiyin written test
选择器的使用语法与场景以及背景图片大小、文字盒子阴影、过度效果的使用方法