初始化毕业设计项目
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#include "stm32f10x_it.h"
|
||||
#include "K210_USART.h" // 包含头文件以使用宏
|
||||
|
||||
// 引用 main.c/K210_USART.c 中定义的全局变量
|
||||
extern volatile char g_k210_rx_buffer[];
|
||||
extern volatile uint16_t g_k210_rx_counter;
|
||||
extern volatile uint8_t g_k210_rx_flag;
|
||||
|
||||
// 引用 Delay.c 中定义的全局时间变量
|
||||
extern volatile uint32_t g_time_ms;
|
||||
|
||||
/**
|
||||
* @brief SysTick中断处理函数(1ms中断一次)
|
||||
* @note 用于维护系统时间戳和延时功能
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
g_time_ms++; // 每1ms递增一次
|
||||
}
|
||||
|
||||
//... HardFault_Handler 等其他中断保持不变 ...
|
||||
|
||||
// USART3中断(来自K210,根据连接图.md: K210使用USART3 PB10/PB11)
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetITStatus(USART3, USART_IT_RXNE) == SET)
|
||||
{
|
||||
uint8_t received_char = USART_ReceiveData(USART3);
|
||||
|
||||
// 收到换行符,认为一帧结束
|
||||
if (received_char == '\n')
|
||||
{
|
||||
if (g_k210_rx_counter > 0)
|
||||
{
|
||||
g_k210_rx_buffer[g_k210_rx_counter] = '\0';
|
||||
g_k210_rx_flag = 1; // 设置标志
|
||||
// 注意:此处不再重置 g_k210_rx_counter,由 K210_GetRxFlag() 负责
|
||||
}
|
||||
}
|
||||
// 忽略回车符
|
||||
else if (received_char != '\r')
|
||||
{
|
||||
if (g_k210_rx_counter < K210_RX_BUFFER_SIZE - 1)
|
||||
{
|
||||
g_k210_rx_buffer[g_k210_rx_counter++] = received_char;
|
||||
}
|
||||
else // 缓冲区满,强制结束
|
||||
{
|
||||
g_k210_rx_buffer[K210_RX_BUFFER_SIZE - 1] = '\0';
|
||||
g_k210_rx_flag = 1;
|
||||
}
|
||||
}
|
||||
USART_ClearITPendingBit(USART3, USART_IT_RXNE);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user