Files
FreeRTOS_LoRa_Environment_A…/STM32/Environment_Node/Drivers/LED.c

36 lines
1.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "LED.h"
void vPc13LedInit(void)
{
RCC_APB2PeriphClockCmd(LED_PC13_GPIO_CLOCK,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = LED_PC13_GPIO_PIN; //PC13
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LED_PC13_GPIO_PORT,&GPIO_InitStructure);
GPIO_SetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN);
}
/* 如果led较多可以定义一个LED_Set函数然后定义两个参数控制一个参数选择操作哪个灯一个参数选择开还是关 */
void vPc13LedOn(void)
{
GPIO_ResetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN);
}
void vPc13LedOff(void)
{
GPIO_SetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN);
}
/* 实现按一下熄灭再按一下点亮该如何实现就是按键按下LED的状态取反实现电平翻转一般用于输出模式下 */
void vPc13LedTurn(void)
{
if(GPIO_ReadOutputDataBit(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN) == 0)//如果PA0的输出寄存器为0
{
GPIO_SetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN); //将PA0置1
}else
{
GPIO_ResetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN);
}
}