www.pudn.com > PMW-HEX-V1.9.rar > PUTCHAR.C, change:2002-02-14,size:2393b


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