25 lines
1.1 KiB
C
25 lines
1.1 KiB
C
/* Includes ----------------------------------------------------------------- */
|
|
#include "task\user_task.h"
|
|
// #include "device/pc.h"
|
|
#include "usart.h" // 添加此行以声明 HAL_UART_Receive 和 huart1
|
|
#include "bsp\led.h"
|
|
|
|
|
|
/* Private variables -------------------------------------------------------- */
|
|
uint16_t adc_data = 0; // 用于存储ADC数据
|
|
/* Exported functions ------------------------------------------------------- */
|
|
void Task_PC(void *argument) {
|
|
(void)argument; // 消除未使用参数的警告
|
|
const uint32_t delay_tick = osKernelGetTickFreq() / 50; // 50Hz
|
|
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
|
|
|
|
while (1) {
|
|
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
|
// 使用 DMA 发送数据
|
|
if (osMessageQueueGet(pcQueueHandle, &adc_data, NULL, osWaitForever) == osOK) {
|
|
// 直接发送数字到PC
|
|
HAL_UART_Transmit_DMA(&huart3, (uint8_t *)&adc_data, sizeof(adc_data));
|
|
}
|
|
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
|
}
|
|
} |