pic单片机使用printf函数

来源:互联网 发布:php微信开发教程 编辑:程序博客网 时间:2024/06/06 15:46
mplab 以及 iar 中printf的问题(下面第一条已验证过雷清生注2017-10-24 20:18)

1、在MPLAB PIC单片机中,要使用PRINTF,要在自己的工程中加入以下函数

void
putch(unsigned char byte)
{
 /* output one byte */
 while(!TXIF) /* set when register is empty */
  continue;
 TXREG = byte;
 
}

然后加上#include <stdio.h>即可

2、在IAR ew8051中,要使用PRINTF,有3个工作

A、工程设置:

generat option/library options/printf format/选 small and mediam;

generate option /stack/heap/stack size/idata/0x60以上,但是,如果太大。系统编译出错。

B、在系统初始化时,使 UTX0IF为1,或者先向串口发一个数。U0DBUF=0X00;

C、加入函数

int putchar (int c)  {
   if (c == '\n')  {
      while (!UTX0IF);
      UTX0IF = 0;
      U0DBUF = 0x0d;       /* output CR  */
   }

   while (!UTX0IF);
   UTX0IF = 0;
   return (U0DBUF = c);
}

阅读全文
0 0