2026/5/25 2:43:54
网站建设
项目流程
丹东网站建设,武极云主机,做招商网站,东莞房价走势图使用任意huart重写int fputc(int ch, FILE *f)
{HAL_UART_Transmit(huart2, (uint8_t *)ch, 1, 0xffff);return ch;
}/*** 函数功能: 重定向c库函数getchar,scanf到DEBUG_USARTx* 输入参数: 无* 返 回 值: 无* 说 明#xff1a;无*/
int fgetc(FILE *f)
{uint8_t…使用任意huart重写int fputc(int ch, FILE *f) { HAL_UART_Transmit(huart2, (uint8_t *)ch, 1, 0xffff); return ch; } /** * 函数功能: 重定向c库函数getchar,scanf到DEBUG_USARTx * 输入参数: 无 * 返 回 值: 无 * 说 明无 */ int fgetc(FILE *f) { uint8_t ch 0; HAL_UART_Receive(huart2, ch, 1, 0xffff); return ch; }需要打开micoLib#include stdio.h #ifdef __GNUC__ #define PUTCHAR_PROTOTYPE int _io_putchar(int ch) #else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif /* __GNUC__*/ /****************************************************************** *brief Retargets the C library printf function to the USART. *param None *retval None ******************************************************************/ PUTCHAR_PROTOTYPE { HAL_UART_Transmit(huart3, (uint8_t *)ch,1,0xFFFF); return ch; }如果不使用MicoLib则需要关闭半主机模式详细见Keil MDK