IAR瑞萨单片机开发加入printf调试函数

IAR开发环境,没有printf函数,自己百度加入了一个(http://www.cnblogs.com/codecamel/p/4686437.html),但是还是有一些问题,特别是打印多个变量时,只能够打印字符串时比较稳定,原因是因为va_arg()给了错误的返回值,故只能找寻其他的方法,今天测试了一下,新的办法步骤如下

1.关键之处,否则会出现PUTCHAR函数未定义现象。

   右键点击工程选择option-> General Option->ibrary configuration中library改为full,且 General Option->library option->Printf formatter选项中选择full2

2. main.c中加入,其中使用的是串口1,注意如果提示FILE未定义,请在头文件最顶层添加#include <stdio.h> 

 1 /* ---------------------------Privatefunction prototypes -----------------------------------------------*/
 2 
 3 #ifdef __GNUC__
 4 /* With GCC/RAISONANCE, small printf(option LD Linker->Libraries->Small printf
 5   set to 'Yes') calls __io_putchar() */
 6 #define PUTCHAR_PROTOTYPE int__io_putchar(int ch)
 7 #else
 8 #define PUTCHAR_PROTOTYPE int fputc(int ch,FILE *f)
 9 #endif /* __GNUC__ */
10 
11 /**
12   *@brief  Retargets the C library printffunction to the USART.
13   *@param  None
14   *@retval None
15   */
16 PUTCHAR_PROTOTYPE
17 {
18   /*Place your implementation of fputc here */
19   /*e.g. write a character to the USART */
20  USART_SendData(EVAL_COM1, (uint8_t) ch);
21   /*Loop until the end of transmission */
22  while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET);
23  return ch;
24 }

printf函数打印字符串,遇到\0时才结束。

 

 

 

转载于:https://www.cnblogs.com/codecamel/p/4741460.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值