printf函数
printf函数支持的代码在SYSTEM文件夹下的usart.c文件中定义了,加入下面的代码就可以通过printf函数向串口发送需要的内容。这段代码不需要修改,只要引入到usart.h即可使用。
- #if 1
- #pragma import(__use_no_semihosting)
- //标准库需要的支持函数
- struct __FILE
- {
- int handle;
-
- };
-
- FILE __stdout;
- //定义_sys_exit()以避免使用半主机模式
- _sys_exit(int x)
- {
- x = x;
- }
- //重定义fputc函数
- int fputc(int ch, FILE *f)
- {
- while((USART1->SR&0X40)==0);//循环发送,直到发送完毕
- USART1->DR = (u8) ch;
- return ch;
- }
- #endif
|