如何在STM32单片机的MDK工程中使用printf

如何在STM32单片机的MDK工程中使用printf,第1张

首先,要包含头文件“stdio.h”

第二:printf()函数使用了int fputc(int ch,FILE *f)完成其功能。

要使用printf,就需要重写这个函数。

第三,在工程选项的Target里边勾选USE MicroLIB项。

fputc示例如下:

int fputc(int ch,FILE *f)

{

/* Place your implementaTIon of fputc here */

/* e.g. write a character to the USART */

USART_SendData(USART1, (uint8_t) ch);

/* Loop unTIl the end of transmission */

while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)

{}

return ch;

}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/dianzi/2587947.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-08-08
下一篇 2022-08-08

发表评论

登录后才能评论

评论列表(0条)

保存