新增 LED 库和串口回显时 LED 闪烁功能
This commit is contained in:
parent
5ab3868114
commit
bc0a2d2034
49
Hardware/led/led.c
Normal file
49
Hardware/led/led.c
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @file led.c
|
||||
* @author Myth
|
||||
* @version 0.1
|
||||
* @date 2021.10.11
|
||||
* @brief stm32f103x6 LED 库
|
||||
*/
|
||||
|
||||
#include "sys.h"
|
||||
#include "systick.h"
|
||||
|
||||
#include "led.h"
|
||||
|
||||
/**
|
||||
* @brief LED 初始化
|
||||
*/
|
||||
void LED_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_Initure;
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE(); //开启 PA 时钟
|
||||
|
||||
GPIO_Initure.Pin = GPIO_PIN_13; //PC13
|
||||
GPIO_Initure.Mode = GPIO_MODE_OUTPUT_PP; //推挽输出
|
||||
GPIO_Initure.Pull = GPIO_PULLUP; //上拉
|
||||
GPIO_Initure.Speed = GPIO_SPEED_FREQ_HIGH; //高速
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_Initure); //初始化 PC13
|
||||
|
||||
LED1_Off;
|
||||
SysTick_StartTimer(LED1_SYSTICK_TIMER_ID, 50);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LED1 慢速翻转,无阻塞,防止因调用过快导致无法观察
|
||||
* @param led_num: 序号
|
||||
*/
|
||||
void LED_Slow_Toggle(uint8_t led_num)
|
||||
{
|
||||
switch (led_num)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if (SysTick_CheckTimer(LED1_SYSTICK_TIMER_ID))
|
||||
{
|
||||
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
|
||||
SysTick_StartTimer(LED1_SYSTICK_TIMER_ID, 50);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Hardware/led/led.h
Normal file
26
Hardware/led/led.h
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @file led.h
|
||||
* @author Myth
|
||||
* @version 0.1
|
||||
* @date 2021.10.11
|
||||
* @brief stm32f103x6 LED 库
|
||||
* @details 提供 LED 开、关、闪烁、慢速闪烁功能
|
||||
* @note LED1: PC13
|
||||
*/
|
||||
|
||||
#ifndef _LED_H
|
||||
#define _LED_H
|
||||
|
||||
#include "sys.h"
|
||||
|
||||
#define LED1(n) (n ? HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET) : HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET))
|
||||
#define LED1_On LED1(0)
|
||||
#define LED1_Off LED1(1)
|
||||
#define LED1_Toggle HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13) //LED1 翻转
|
||||
#define LED1_SYSTICK_TIMER_ID 0
|
||||
#define LED1_Slow_Toggle LED_Slow_Toggle(1) //LED1 慢速翻转,无阻塞,防止因调用过快导致无法观察
|
||||
|
||||
void LED_Init(void);
|
||||
void LED_Slow_Toggle(uint8_t led_num);
|
||||
|
||||
#endif
|
||||
@ -339,7 +339,7 @@
|
||||
<MiscControls></MiscControls>
|
||||
<Define>USE_HAL_DRIVER, STM32F103x6</Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>..\Core;..\Libraries\HAL_Lib\Inc;..\User\Main;..\System\sys;..\System\systick;..\System\uart</IncludePath>
|
||||
<IncludePath>..\Core;..\Libraries\HAL_Lib\Inc;..\User\Main;..\System\sys;..\System\systick;..\System\uart;..\Hardware\led</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
<Aads>
|
||||
@ -657,6 +657,13 @@
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>Hardware</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>led.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\Hardware\led\led.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
</Groups>
|
||||
</Target>
|
||||
|
||||
@ -5,13 +5,15 @@
|
||||
* @date 2021.10.11
|
||||
* @brief 工程主函数文件
|
||||
* @details 初始化及主循环
|
||||
* @note 工程模版实现的功能:串口回显
|
||||
* @note 工程模版实现的功能:串口回显,回显时 PC13 上的 LED 闪烁
|
||||
*/
|
||||
|
||||
#include "sys.h"
|
||||
#include "systick.h"
|
||||
#include "uart.h"
|
||||
|
||||
#include "led.h"
|
||||
|
||||
void Echo(uint8_t byte);
|
||||
|
||||
int main(void)
|
||||
@ -24,6 +26,8 @@ int main(void)
|
||||
SysTick_Init(); //初始化 SysTick 和软件定时器
|
||||
UART_Init(); //初始化串口
|
||||
|
||||
LED_Init(); //初始化 LED
|
||||
|
||||
UART_BindReceiveHandle(COM1, Echo); //绑定 COM1 串口接收中断至 Echo 函数
|
||||
|
||||
while (1)
|
||||
@ -40,5 +44,6 @@ int main(void)
|
||||
*/
|
||||
void Echo(uint8_t byte)
|
||||
{
|
||||
LED1_Toggle;
|
||||
UART_SendChar(COM1, byte);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user