当前位置:网站首页>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 .
边栏推荐
- Educational Codeforces Round 132 (Rated for Div. 2), problem: (D) Rorororobot
- ACM模式输入输出练习
- HCIA (network elementary comprehensive experimental exercise)
- Static routing default routing VLAN experiment
- 6.29 众安暑期测开实习一面
- 7.13 Weilai approved the written examination in advance
- 通过对射式红外传感器计次实验讲解EXTI中断
- 2022最新抖音直播监控(二)直播间流媒体下载
- 6.30滴滴面经(一面+二面)
- Solution: various error reports and pit stepping and pit avoidance records encountered in the alchemist cultivation plan pytoch+deeplearning (II)
猜你喜欢

Tcp的三次握手与四次挥手

C语言——关系运算符和逻辑运算符、if语句、switch语句、分支结构的嵌套

VLAN原理简述、具体实验配置

Brief introduction of VLAN principle and specific experimental configuration

Text to image paper intensive reading rat-gan: recursive affine transformation for text to image synthesis

【数据库课程设计】SQLServer数据库课程设计(学生宿舍管理),课设报告+源码+数据库关系图

Text to image intensive reading df-gan:a simple and effective baseline for text to image synthesis
npm报错, Error: EPERM: operation not permitted, mkdir

The latest C language introduction and advanced - the most complete and detailed C language tutorial in history!! Section 1 - overview of C language

HCIA(网络初级综合实验练习)
随机推荐
静态综合实验(静态路由、环回接口、缺省路由、空接口、浮动静态的综合练习)
HCIA基础知识(1)
静态路由综合实验
Electron FAQ 61 - must the client run with administrator privileges?
机械硬盘选购指南——从选购经历谈起
平面转换(位移、旋转、缩放)
STM32 HAL库串口(UART/USART)调试经验(一)——串口通信基础知识+HAL库代码理解
[explain C language in detail] takes you to play with the choice (Branch) structure
TCP的三次握手与四次断开
[volatile principle] volatile principle
VLAN原理简述、具体实验配置
Codeforces Round #810 (Div. 2), problem: (B) Party
[FPGA tutorial case 29] the second DDS direct digital frequency synthesizer based on FPGA - Verilog development
6.30 written examination of MediaTek
7.16 多益网络笔试
选择器的使用语法与场景以及背景图片大小、文字盒子阴影、过度效果的使用方法
ACM模式输入输出练习
HCIA (network elementary comprehensive experimental exercise)
Text to image paper intensive reading rat-gan: recursive affine transformation for text to image synthesis
2022zui新抖音24小时循环值守直播监控(一)直播间开播监控