SMT32控制IO时,模式和速度如果一样可以省略
来源:互联网 发布:从零开始学英语 知乎 编辑:程序博客网 时间:2024/06/05 13:00
#include "led.h"
#include "stm32f10x.h"
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //定义一个GPIO初始化结构体
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); //PB口时钟使能
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG,ENABLE); //PG口时钟使能
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE); //PF口时钟使能
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); //PC口时钟使能
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); //PE口时钟使能
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOG | RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //设置第13管脚
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOB, GPIO_Pin_13); //设置PB13管脚输出高电平
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //设置第0管脚
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOG, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOG, GPIO_Pin_0); //设置PG0管脚输出高电平
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; //设置第14管脚
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOF, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOF, GPIO_Pin_14); //设置PF14管脚输出高电平
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //设置第12管脚
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOF, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOF, GPIO_Pin_12); //设置PF12管脚输出高电平
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //设置第2管脚
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOB, GPIO_Pin_2); //设置PB2管脚输出高电平
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //设置第0管脚
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOB, GPIO_Pin_0); //设置PB0管脚输出高电平
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //设置第4管脚
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOC, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOC, GPIO_Pin_4); //设置PC0管脚输出高电平
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //设置第5管脚
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOA, GPIO_Pin_6); //设置PA6管脚输出高电平
}
#include "stm32f10x.h"
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //定义一个GPIO初始化结构体
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); //PB口时钟使能
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG,ENABLE); //PG口时钟使能
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE); //PF口时钟使能
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); //PC口时钟使能
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); //PE口时钟使能
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOG | RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOA,ENABLE);
这里五行代码用一行就可以了,用 | ,体现了算法的精妙!
//下面的用到的IO口工作模式和速度都是一样的,所以设置一次就行
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //设置第13管脚
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOB, GPIO_Pin_13); //设置PB13管脚输出高电平
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //设置第0管脚
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOG, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOG, GPIO_Pin_0); //设置PG0管脚输出高电平
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; //设置第14管脚
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOF, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOF, GPIO_Pin_14); //设置PF14管脚输出高电平
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //设置第12管脚
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOF, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOF, GPIO_Pin_12); //设置PF12管脚输出高电平
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //设置第2管脚
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOB, GPIO_Pin_2); //设置PB2管脚输出高电平
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //设置第0管脚
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOB, GPIO_Pin_0); //设置PB0管脚输出高电平
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //设置第4管脚
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOC, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOC, GPIO_Pin_4); //设置PC0管脚输出高电平
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //设置第5管脚
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置速度50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(GPIOA, GPIO_Pin_6); //设置PA6管脚输出高电平
}
0 0
- SMT32控制IO时,模式和速度如果一样可以省略
- 如果将synthesize省略,语义特性声明为assign retain copy时,自己实现setter和getter方法
- 如果将synthesize省略,语义特性声明为assign retain copy时,自己实现setter和getter方法
- 适配器模式-不会英语一样可以泡洋妞
- SMT32通过I2C和EP4C通信的问题
- nio.FileChannel 、io.Stream 和 io.buffer速度的比较
- IO和Decorator模式
- viewPager控制滑动速度和时间
- css控制一行文字超出省略
- 有IO速度限制的cp和mv
- 为什么在iOS上访问优酷和土豆一样可以播放呢?
- linux查看网卡速度和模式调整
- IO多路复用和Reactor模式
- IO多路复用和Reactor模式
- javascript构造函数如果没有形参允许省略圆括号
- 标准IO输出_api和格式控制
- 关于RecyclerView滑动速度和抛掷速度的控制和改变
- IO读取速度测试
- win10+TensorFlow版yolov1使用方法
- good news
- mac下搭建git服务器
- source insight
- allegro等长规则设定中的Delta-Tolerance
- SMT32控制IO时,模式和速度如果一样可以省略
- 156_07_集合_Collection集合的常用方法详解_04_remove
- 爬虫进阶深入目标
- 原生js再不写就忘了?纯JavaScript操作DOM!
- 水题
- 【程序员修炼日志】初接项目的心酸(下技术篇)
- Node.js中的模块
- oracle空串处理(转载)
- C++——const加深理解之const在函数后