IAR瑞薩單片機開發加入printf調試函數

IAR開發環境,沒有printf函數,本身百度加入了一個(http://www.cnblogs.com/codecamel/p/4686437.html),可是仍是有一些問題,特別是打印多個變量時,只可以打印字符串時比較穩定,緣由是由於va_arg()給了錯誤的返回值,故只能找尋其餘的方法,今天測試了一下,新的辦法步驟以下html

1.關鍵之處,不然會出現PUTCHAR函數未定義現象。函數

   右鍵點擊工程選擇option-> General Option->ibrary configuration中library改成full,且 General Option->library option->Printf formatter選項中選擇full2oop

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時才結束。ui

相關文章
相關標籤/搜索