82 lines
2.6 KiB
C
82 lines
2.6 KiB
C
#include "led.h"
|
||
|
||
int Led_Count=500; //LED flicker time control //LED闪烁时间控制
|
||
|
||
/**************************************************************************
|
||
Function: LED interface initialization
|
||
Input : none
|
||
Output : none
|
||
函数功能:LED接口初始化
|
||
入口参数:无
|
||
返回 值:无
|
||
**************************************************************************/
|
||
void LED_Init(void)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
|
||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//使能GPIOB时钟
|
||
GPIO_InitStructure.GPIO_Pin = LED_PIN;//LED对应IO口
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通输出模式
|
||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
|
||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
|
||
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIO
|
||
GPIO_SetBits(GPIOA,GPIO_Pin_12);
|
||
}
|
||
/**************************************************************************
|
||
Function: Buzzer interface initialized
|
||
Input : none
|
||
Output : none
|
||
函数功能:蜂鸣器接口初始化
|
||
入口参数:无
|
||
返回 值:无
|
||
**************************************************************************/
|
||
void Buzzer_Init(void)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure;
|
||
|
||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//使能GPIOB时钟
|
||
GPIO_InitStructure.GPIO_Pin = Buzzer_PIN;//LED对应IO口
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通输出模式
|
||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
|
||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
|
||
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIO
|
||
}
|
||
/**************************************************************************
|
||
Function: LED light flashing task
|
||
Input : none
|
||
Output : none
|
||
函数功能:LED灯闪烁任务
|
||
入口参数:无
|
||
返回 值:无
|
||
**************************************************************************/
|
||
void led_task(void *pvParameters)
|
||
{
|
||
while(1)
|
||
{
|
||
//The status of the LED is reversed. 0 is on and 1 is off
|
||
//LED状态取反,0是点亮,1是熄灭
|
||
LED=~LED;
|
||
//The LED flicker task is very simple, requires low frequency accuracy, and uses the relative delay function
|
||
//LED闪烁任务非常简单,对频率精度要求低,使用相对延时函数
|
||
vTaskDelay(Led_Count);
|
||
}
|
||
}
|
||
|
||
/**************************************************************************
|
||
Function: The LED flashing
|
||
Input : none
|
||
Output : blink time
|
||
函数功能:LED闪烁
|
||
入口参数:闪烁时间
|
||
返 回 值:无
|
||
**************************************************************************/
|
||
void Led_Flash(u16 time)
|
||
{
|
||
static int temp;
|
||
if(0==time) LED=0;
|
||
else if(++temp==time) LED=~LED,temp=0;
|
||
}
|
||
|