使用BSRR和BRR熄灭和点亮LED灯

//以下是在stm32f10x_gpio.c文件下的

#include "stm32f10x_gpio.h"

//BSRR置位函数
void GPIO_SetBits (GPIO_TypeDef *GPIOx,uint32_t GPIO_Pin)
{
    GPIOx->BSRR |=GPIO_Pin;
}


//BRR复位函数
void GPIO_RetsetBits    (GPIO_TypeDef *GPIOx,uint32_t GPIO_Pin)
{
        GPIOx->BRR |=GPIO_Pin;

}
*****************************************************************************************************

//定义函数以及置为和复位的端口均在stm32f10x_gpio.h文件下

#ifndef _STM32F10X_GPIO_H
#define _STM32F10X_GPIO_H

#include "stm32f10x.h"

#define GPIO_Pin_0            ((uint32_t)0x0001)
#define GPIO_Pin_1            ((uint32_t)0x0002)
#define GPIO_Pin_2            ((uint32_t)0x0004)
#define GPIO_Pin_3            ((uint32_t)0x0008)
#define GPIO_Pin_4            ((uint32_t)0x0010)
#define GPIO_Pin_5            ((uint32_t)0x0020)
#define GPIO_Pin_6            ((uint32_t)0x0040)
#define GPIO_Pin_7            ((uint32_t)0x0080)
#define GPIO_Pin_8            ((uint32_t)0x0100)
#define GPIO_Pin_9            ((uint32_t)0x0200)
#define GPIO_Pin_10            ((uint32_t)0x0400)
#define GPIO_Pin_11            ((uint32_t)0x0800)
#define GPIO_Pin_12            ((uint32_t)0x1000)
#define GPIO_Pin_13            ((uint32_t)0x2000)
#define GPIO_Pin_14            ((uint32_t)0x4000)
#define GPIO_Pin_15            ((uint32_t)0x8000)
#define GPIO_Pin_ALL        ((uint32_t)0xffff)

void GPIO_SetBits (GPIO_TypeDef *GPIOx,uint32_t GPIO_Pin);

void GPIO_RetsetBits    (GPIO_TypeDef *GPIOx,uint32_t GPIO_Pin);

#endif

**********************************************************************************************

main.c里直接调用函数即可

GPIO_SetBits (GPIOB,GPIO_Pin_0);  //使用端口置位函数熄灭LED
GPIO_RetsetBits    (GPIOB,GPIO_Pin_0);      //使用端口复位函数点亮LED,低电平点亮

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值