stm32有強大的庫文件,單片機輸出字符串時,可使用printf()代替,方便簡潔並且便於閱讀ui
簡單配置步驟字符串
1,頭文件添加it
#include <stdio.h>io
2,main.c 添加配置
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */程序
//主程序call
int main()
{
.........
printf("haha\n");di
}文件
//這裏就是設置 printf 對應的串口while
PUTCHAR_PROTOTYPE{ USART_SendData(USART2, (uint8_t) ch); //這個就是要輸出用到串口 while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET) {} return ch;}