代码
在main.c中,添加头文件,若不添加会出现 identifier “FILE” is undefined报错。
/* USER CODE BEGIN Includes */
#include "stdio.h"
/* USER CODE END Includes */
红外接收口定义
/* USER CODE BEGIN PTD */
#define IR_IN1 HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_9)
/* USER CODE END PTD */
函数声明和串口重定向:
/* USER CODE BEGIN PFP */
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit(&huart1 , (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
uint32_t OrderData = 0;
uint8_t ReadyFlag = 0;
uint8_t OK = 0;
/* USER CODE END 0 */
定时器配置
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim1);//启动定时器
HAL_TIM_IC_Start_IT(&htim1,TIM_CHANNEL_2);//函数用于使能定时器某一通道的输入捕获功能,并使能相应的中断
printf("IR Capture !! \r\n");
/* USER CODE END 2 *