使用printf向串口输出数据

来源:互联网 发布:广州达内java培训 编辑:程序博客网 时间:2024/06/07 13:05

引自 http://www.stmfans.com/bbs/viewthread.php?tid=505&extra=page%3D2

要在IAR中使用printf向串口输出数据,需要加入如下的函数原型,它的目的是将printf指向串口一这个设备并向这个设备输出数据。

#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__ */


PUTCHAR_PROTOTYPE
{
/* Write a character to the USART */
  USART_SendData(USART1, (u8) ch);

  /* Loop until the end of transmission */
  while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)  {
  }

  return ch;
}

0 0
原创粉丝点击