C51中 Putchar、 _getkey(void)的替换

来源:互联网 发布:java与php的优缺点 编辑:程序博客网 时间:2024/06/05 11:38
1、拷贝KEIL C51下LIB目录中的PUTCHAR.C和GETKEY.C文件到你的项目目录下,并且将其添加到你的工程中
2、PUTCHAR.C原代码如下
/***********************************************************************//*  This file is part of the C51 Compiler package                      *//*  Copyright KEIL ELEKTRONIK GmbH 1990 - 2002                         *//***********************************************************************//*                                                                     *//*  PUTCHAR.C:  This routine is the general character output of C51.   *//*  You may add this file to a uVision2 project.                       *//*                                                                     *//*  To translate this file use C51 with the following invocation:      *//*     C51 PUTCHAR.C <memory model>                                    *//*                                                                     *//*  To link the modified PUTCHAR.OBJ file to your application use the  *//*  following Lx51 invocation:                                         *//*     Lx51 <your object file list>, PUTCHAR.OBJ <controls>            *//*                                                                     *//***********************************************************************/#include <reg51.h>#define XON  0x11#define XOFF 0x13/* * putchar (full version):  expands '\n' into CR LF and handles *                          XON/XOFF (Ctrl+S/Ctrl+Q) protocol */char putchar (char c)  {  if (c == '\n')  {    if (RI)  {      if (SBUF == XOFF)  {        do  {          RI = 0;          while (!RI);        }        while (SBUF != XON);        RI = 0;       }    }    while (!TI);    TI = 0;    SBUF = 0x0d;                         /* output CR  */  }  if (RI)  {    if (SBUF == XOFF)  {      do  {        RI = 0;        while (!RI);      }      while (SBUF != XON);      RI = 0;     }  }  while (!TI);  TI = 0;  return (SBUF = c);}#if 0         // comment out versions below/* * putchar (basic version): expands '\n' into CR LF */char putchar (char c)  {  if (c == '\n')  {    while (!TI);    TI = 0;    SBUF = 0x0d;                         /* output CR  */  }  while (!TI);  TI = 0;  return (SBUF = c);}/* * putchar (mini version): outputs charcter only */char putchar (char c)  {  while (!TI);  TI = 0;  return (SBUF = c);}#endif

修改后PUTCHAR.C代码如下:

extern void Serial_Out(unsigned char Serial_Out_Data);//自编<span style="font-family: Arial;">以中断方式</span>向指定的串行口输出一个字节void  putchar (char c)  {Serial_Out(c);//<span style="font-family: Arial;">自编</span>以中断方式向指定的串行口输出一个字节}
3、GETKEY.C原代码如下
/***********************************************************************//*  This file is part of the C51 Compiler package                      *//*  Copyright KEIL ELEKTRONIK GmbH 1993 - 2002                         *//***********************************************************************//*                                                                     *//*  GETKEY.C:  This routine is the general character input of C51.     *//*  You may add this file to a uVision2 project.                       *//*                                                                     *//*  To translate this file use C51 with the following invocation:      *//*     C51 GETKEY.C  <memory model>                                    *//*                                                                     *//*  To link the modified GETKEY.OBJ file to your application use the   *//*  following Lx51 invocation:                                         *//*     Lx51 <your object file list>, GETKEY.OBJ <controls>             *//*                                                                     *//***********************************************************************/#include <reg51.h>char _getkey ()  {  char c;  while (!RI);  c = SBUF;  RI = 0;  return (c);}
修改后GETKEY.C代码如下:
extern unsigned char Serial_In(void);char _getkey ()  {  char c;c=Serial_In();  return (c);}
4、编译你的项目即可完成 对void putchar (char c)和_getkey ()的替换


5、可将_getkey ()改写为按键输入,也可将putchar (char c)改为向LCD屏输出






0 0
原创粉丝点击