#include "stm32f10x_gpio.h"
void GPIO_SetBit(GPIO_TypeDef *GPIOx,uint16_t GPIO_Pin)
{
GPIOx->BSRR |= GPIO_Pin;
}
void GPIO_ResetBit(GPIO_TypeDef *GPIOx,uint16_t GPIO_Pin)
{
GPIOx->BRR |=GPIO_Pin;
}
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
{
uint32_t currentmode = 0x00, currentpin = 0x00, pinpos = 0x00, pos = 0x00;
uint32_t tmpreg = 0x00, pinmask = 0x00;
/* Check the parameters */
// assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
// assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
// assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
/*---------------------------- GPIO Mode Configuration -----------------------*/
currentmode = ((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x0F);
if ((((uint32_t)GPIO_InitStruct->GPIO_Mode) & ((uint32_t)0x10)) != 0x00)
{
/* Check the parameters */
// assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));
/* Output mode */
currentmode |= (uint32_t)GPIO_InitStruct->GPIO_Speed;
}
/*---------------------------- GPIO CRL Configuration ------------------------*/
/* Configure the eight low port pins */
if (((uint32_t)GPIO_InitStruct->GPIO_Pin & ((uint32_t)0x00FF)) != 0x00)
{
tmpreg = GPIOx->CRL;
for (pinpos = 0x00; pinpos < 0x08; pinpos++)
{
pos = ((uint32_t)0x01) << pinpos;
/* Get the port pins position */
currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
if (currentpin == pos)
{
pos = pinpos << 2;
/* Clear the corresponding low control register bits */
pinmask = ((uint32_t)0x0F) << pos;
tmpreg &= ~pinmask;
/* Write the mode configuration in the corresponding bits */
tmpreg |= (currentmode << pos);
/* Reset the corresponding ODR bit */
if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)
{
GPIOx->BRR = (((uint32_t)0x01) << pinpos);
}
else
{
/* Set the corresponding ODR bit */
if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)
{
GPIOx->BSRR = (((uint32_t)0x01) << pinpos);
}
}
}
}
GPIOx->CRL = tmpreg;
}
/*---------------------------- GPIO CRH Configuration ------------------------*/
/* Configure the eight high port pins */
if (GPIO_InitStruct->GPIO_Pin > 0x00FF)
{
tmpreg = GPIOx->CRH;
for (pinpos = 0x00; pinpos < 0x08; pinpos++)
{
pos = (((uint32_t)0x01) << (pinpos + 0x08));
/* Get the port pins position */
currentpin = ((GPIO_InitStruct->GPIO_Pin) & pos);
if (currentpin == pos)
{
pos = pinpos << 2;
/* Clear the corresponding high control register bits */
pinmask = ((uint32_t)0x0F) << pos;
tmpreg &= ~pinmask;
/* Write the mode configuration in the corresponding bits */
tmpreg |= (currentmode << pos);
/* Reset the corresponding ODR bit */
if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)
{
GPIOx->BRR = (((uint32_t)0x01) << (pinpos + 0x08));
}
/* Set the corresponding ODR bit */
if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)
{
GPIOx->BSRR = (((uint32_t)0x01) << (pinpos + 0x08));
}
}
}
GPIOx->CRH = tmpreg;
}
}
/**
* @brief Fills each GPIO_InitStruct member with its default value.
* @param GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure which will
* be initialized.
* @retval None
*/
没有合适的资源?快使用搜索试试~ 我知道了~
STM32入门-构建库函数源码压缩文件
共32个文件
htm:4个
o:3个
d:3个
需积分: 0 0 下载量 75 浏览量
2024-01-15
20:09:23
上传
评论
收藏 76KB ZIP 举报
温馨提示
本资源是一份STM32入门级别的库函数源码压缩文件,旨在帮助初学者快速入门STM32开发,并提供了一些常用功能的库函数示例代码。该压缩文件包含了STM32系列芯片的库函数源码及相关示例程序,主要是GPIO控制功能。本资源适用于对嵌入式系统开发有一定了解,希望深入学习STM32单片机编程的初学者。无论是学生、工程师还是爱好者,只要掌握了C语言基础和嵌入式系统原理,都可以通过本资源快速上手STM32开发。资源的主要目标是帮助初学者熟悉STM32开发环境和库函数的使用方法。通过学习本资源中的源码示例,初学者可以了解如何初始化STM32芯片、配置外设、实现常见功能等。这些示例代码可以作为学习STM32的基础,帮助初学者逐步掌握STM32开发技巧。本资源为压缩文件形式,需要下载后解压缩才能使用。压缩文件中包含了库函数源码及示例程序,但不包含编译工具链。使用者需要自行准备开发工具。本资源提供的示例代码是基于常用的STM32F103ZET6开发板进行编写的,对于其他型号的STM32芯片可能需要做适当的修改。希望本资源能够帮助初学者快速入门STM32开发,为他们打开嵌入式系统开发的大门!
资源推荐
资源详情
资源评论
收起资源包目录
FWlib-LED.zip (32个子文件)
FWlib-LED
stm32f10x_gpio.c 4KB
Objects
Template-REG.build_log.htm 2KB
BH-F103_Template-REG.dep 1KB
BH-F103_Target 1.dep 800B
Template-REG.axf 20KB
startup_stm32f10x_hd.o 7KB
Template-REG.hex 3KB
stm32f10x_gpio.crf 3KB
BH-F103.axf 15KB
BH-F103.build_log.htm 1KB
BH-F103.htm 38KB
BH-F103.sct 479B
stm32f10x_gpio.o 13KB
main.d 93B
main.o 13KB
stm32f10x_gpio.d 133B
startup_stm32f10x_hd.d 58B
Template-REG.sct 479B
Template-REG.htm 39KB
BH-F103.lnp 303B
main.crf 3KB
Template-REG.lnp 348B
BH-F103.uvguix.01 85KB
BH-F103.uvprojx 14KB
startup_stm32f10x_hd.s 15KB
Listings
startup_stm32f10x_hd.lst 48KB
BH-F103.map 52KB
Template-REG.map 54KB
stm32f10x.h 2KB
stm32f10x_gpio.h 2KB
main.c 3KB
BH-F103.uvoptx 7KB
共 32 条
- 1
资源评论
m0_20230122
- 粉丝: 281
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 上市公司-人工智能的采纳程度面板数据(2003-2021年).xlsx
- 第5章spring-mvc请求映射处理
- 2023-04-06-项目笔记 - 第一百十六阶段 - 4.4.2.114全局变量的作用域-114 -2024.04.27
- app-release.apk.1
- soap json 等系列化方式
- c++的五子棋代码,在vs6.0上完美运行
- 基于Javaee的影视创作论坛的设计与实现.rar
- Python导出Mysql数据字典(部分表或全表)
- Java工具类实现输入一个路径,强创建路径、并且鉴权目标路径是否具备修改权限,用于增强程序的健壮性与稳定性,快速开发!
- 资源【STM32+HAL】三轴按键PS2摇杆
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功