首页 > 技术文章 > STM32单片机(7) 串口通信printf重定向

leytton 2014-08-06 02:16 原文

【转载请注明出处:http://blog.csdn.net/leytton/article/details/38393967

视频教程

http://v.pps.tv/play_38CV0A.html?sort=desc


此处是为了在串口中断通信[参见另一篇文章]中添加printf重定向功能

1、添加头文件  #include <stdio.h>

2、工程“Target" -->勾选 "Use MicroLIB"

3、重定义fputc函数

int fputc(int ch, FILE *f)
{
Uart1_PutChar((u8)ch);  //此处为自定义函数,参见串口中断通信,请勿盲目复制
return (ch);
}

经过上述配置后即可在项目中使用printf("Hello~");等来发送字符串了

(printf("<格式化字符串>", <参量表>) 与C语言使用一样)






推荐阅读