SY/USER/Led/Led.c
ecol 1da6dcb89c 综合实验完成
添加系统状态显示LED

将pwm控制放到了定时器中断里

改变开关为控制系统开关

在按键中断里加入了整个系统的开关控制

修改并优化了电路图
2020-05-26 09:29:43 +08:00

61 lines
2.0 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"
/**-------------------------------------------------------
* @函数名 LED_GPIO_INIT
* @功能 LED GPIO初始化
* @返回值 无
***------------------------------------------------------*/
void LED_GPIO_INIT(void){
GPIO_InitTypeDef GPIO_InitStructure;
/* 使能LED对应GPIO的时钟 */
RCC_APB2PeriphClockCmd(LED_CLOCK, ENABLE); //使能对应端口时钟
/* 初始化LED的GPIO管脚,配置为推挽输出 */ //设置端口
GPIO_InitStructure.GPIO_Pin = LED_Pin_ALL; //LED所有引脚
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设置为推挽(Push-Pull)输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //最大输出速度为50MHz
GPIO_Init(LED_PORT, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_SetBits(LED_PORT,LED_Pin_ALL); //led全灭
/* 初始化LED的GPIO管脚,配置为推挽输出 */ //设置端口
GPIO_InitStructure.GPIO_Pin = LED_SYS_Pin; //LED所有引脚
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设置为推挽(Push-Pull)输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //最大输出速度为50MHz
GPIO_Init(LED_SYS_PORT, &GPIO_InitStructure); //调用GPIO初始化函数
GPIO_ResetBits(LED_SYS_PORT,LED_SYS_Pin); //点亮系统指示灯
}
/**-------------------------------------------------------
* @函数名 LED_ON
* @功能 点亮指定LED LED0,1,2,3
* @返回值 无
***------------------------------------------------------*/
void LED_ON(u8 n){
uint16_t GPIO_PIN_LIST[]={LED2_Pin,LED3_Pin,LED4_Pin,LED5_Pin};
u8 i;
for(i=0;i<4;i++)
{
GPIO_SetBits(LED_PORT,GPIO_PIN_LIST[i]);
}
GPIO_ResetBits(LED_PORT,GPIO_PIN_LIST[n]);
}
/**-------------------------------------------------------
* @函数名 LED_OFF
* @功能 关闭所有LED
* @返回值 无
***------------------------------------------------------*/
void LED_OFF(void){
uint16_t GPIO_PIN_LIST[]={LED2_Pin,LED3_Pin,LED4_Pin,LED5_Pin};
u8 i;
for(i=0;i<4;i++)
{
GPIO_SetBits(LED_PORT,GPIO_PIN_LIST[i]);
}
}