IAR中通过串口使用printf函数

来源:互联网 发布:windows系统编程基础 编辑:程序博客网 时间:2024/05/29 19:16

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

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

2. main.c中加入,其中使用的是串口1

/* ---------------------------Privatefunction prototypes -----------------------------------------------*/

#ifdef __GNUC__

/* With GCC/RAISONANCE, small printf(option LD Linker->Libraries->Small printf

  set to 'Yes') calls __io_putchar() */

#define PUTCHAR_PROTOTYPE int__io_putchar(int ch)

#else

#define PUTCHAR_PROTOTYPE int fputc(int ch,FILE *f)

#endif /* __GNUC__ */


 

/**

  *@brief  Retargets the C library printffunction to the USART.

  *@param  None

  *@retval None

  */

PUTCHAR_PROTOTYPE

{

  /*Place your implementation of fputc here */

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

 USART_SendData(EVAL_COM1, (uint8_t) ch);

 

  /*Loop until the end of transmission */

 while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET);

 

 return ch;

}


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

原创粉丝点击