<strong>1、概述</strong>
<strong>GPIO相关特征概述:</strong>
- STM32F030提供55个快速IO口,分为5组(A、B、C、D、F)
- 每 个 通 用 I/O 口 都 有 4 个 32 位 配 置 寄 存 器(GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR 和 GPIOx_PUPDR), 2 个 32 位数据寄存器 (GPIOx_IDR and GPIOx_ODR) 和 1 个32 位置位 / 复位寄存器 (GPIOx_BSRR)
- 输出状态: 带有上拉或下拉的推挽输出或开漏输出
- 可选的每个 I/O 口的速度
- 输入状态: 浮空、 上拉 / 下拉、 模拟输入
- 模拟功能
- 复用功能
<strong>LED相关特征概述: </strong>
- LED低电平点亮
- PA2 PA3 连接LED1 LED2
<strong>2、准备工作</strong>
建议准备F0的参考手册和数据手册,方便查阅相关知识,没有的请到ST官网或到我的CSDN下载。
我每次都会提供整理好的软件工程供大家下载,但是,如果你是一位学习者,建议自己亲手一步一步操作:打开工程 -> 新建文件(led.c led.h) -> 添加相关文件到工程中 -> 添加源代码。
<strong>3、寄存器说明</strong>
这里我只简单的说明几个常用的寄存器的功能配置,其他寄存器的配置还需查看STM32F030的数据手册。
<strong>GPIO 端口模式寄存器 (GPIOx_MODER) (x = A..D,F) </strong>
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006503-20200-bc1.png" alt=“1” width="600"></center>
<strong>GPIO 端口输出类型寄存器 (GPIOx_OTYPER) (x = A..D,F) </strong>
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006503-20201-bc2.png" alt=“2” width="600"></center>
<strong>GPIO 口输出速度寄存器 (GPIOx_OSPEEDR) (x = A..D,F)</strong>
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006503-20202-bc3.png" alt=“3” width="600"></center>
<strong>GPIO 口上拉 / 下拉寄存器 (GPIOx_PUPDR) (x = A..D,F) </strong>
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006503-20203-bc4.png" alt=“4” width="600"></center>
<strong>GPIO 端口置位 / 复位寄存器 (GPIOx_BSRR) (x = A..D,F) </strong>
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006503-20204-bc5.png" alt=5“” width="600"></center>
<strong>GPIO 复用功能低位寄存器 (GPIOx_AFRL) (x = A..B)</strong>
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006503-20205-bc6.png" alt=“6” width="600"></center>
<strong>GPIO 复用功能高位寄存器 (GPIOx_AFRH) (x = A..B) </strong>
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006503-20206-bc7.png" alt=“7” width="600"></center>
<strong>端口位复位寄存器 (GPIOx_BRR) (x=A..G) </strong>
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006503-20207-bc8.png" alt=“8” width="600"></center>
<strong>4、LED配置</strong>
<strong>LED原理图</strong>
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006503-20208-bc9.png" alt=“9” width="600"></center>
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006503-20209-bc10.png" alt=“10” width="600"></center>
<strong>代码描述 </strong>
①LED初始化
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006503-20210-bc11.png" alt=“11” width="600"></center>
该函数在led.c文件下,
RCC_AHBPeriphClockCmd()是GPIO时钟控制的库函数封装
②LED1/2的打开或者关闭的宏定义函数
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006503-20211-bc12.png" alt=“12” width="600"></center>
该函数在led.h文件下,
③主函数main
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006503-20212-bc13.png" alt=“13” width="600"></center>
④实验现象
每0.5秒LED1进行翻转,闪烁点亮
<strong>5、说明</strong>
本次文档使用的单片机型号为STM32F030R8T6,如果是其他版本的请详细参考原理图和数据手册,一般只需修改LED1/2(PA2/3)的GPIO管脚。
本文转载自<a href="http://blog.csdn.net/qq_29653157/article/details/69944976">晗生缘</a>