itloverhpu

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

1.使用printf库函数时,要加入头文件<stdio.h>

2.另外在keil里面需要把:use MicroLIB 勾选上,不然程序没办法在线调试。编译的时候不会报错。

3.当然可以不用库函数,自己写。正点原子里面的代码:

 //加入以下代码,支持printf函数,而不需要选择use MicroLIB

#if 1
 #pragma import(__use_no_semihosting)
 //标准库需要的支持函数
struct __FILE
{
  int handle;

};

FILE __stdout;
//定义_sys_exit()以避免使用半主机模式
_sys_exit(int x)
{
  x = x;
}
//重定义fputc函数
int fputc(int ch, FILE *f)
{
  while((USART1->SR&0X40)==0);//循环发送,直到发送完毕
  USART1->DR = (u8) ch;
  return ch;
}
#endif

/*使用microLib的方法*/
/*
int fputc(int ch, FILE *f)
{
  USART_SendData(USART1, (uint8_t) ch);

  while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) {}
  return ch;
}
int GetKey (void)

{

  while (!(USART1->SR & USART_FLAG_RXNE));

  return ((int)(USART1->DR & 0x1FF));
}
*/

posted on 2013-10-10 14:52  itloverhpu  阅读(573)  评论(0编辑  收藏  举报