home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 September / PCWK996.iso / demo / wgelectr / pk51demo / files.2 / EXAMPLES / SAMPL517 / PUTCHAR.C < prev    next >
C/C++ Source or Header  |  1995-06-08  |  2KB  |  54 lines

  1. /***********************************************************************/
  2. /* Copyright 1995 KEIL Software, Inc.                                  */
  3. /***********************************************************************/
  4. /*                                                                     */
  5. /*  PUTCHAR.C:  This routine is the general character output of C51.   */
  6. /*                                                                     */
  7. /*  To translate this file use C51 with the following invocation:      */
  8. /*                                                                     */
  9. /*     C51 PUTCHAR.C                                                   */
  10. /*                                                                     */
  11. /*  To link the modified PUTCHAR.OBJ file to your application use the  */
  12. /*  following BL51 invocation:                                         */
  13. /*                                                                     */
  14. /*     BL51 <your object file list>, PUTCHAR.OBJ <controls>            */
  15. /*                                                                     */
  16. /***********************************************************************/
  17.  
  18. #include <reg517.h>
  19.  
  20. #define XON  0x11
  21. #define XOFF 0x13
  22.  
  23. char putchar (char c)  {
  24.  
  25.   if (c == '\n')  {
  26.     if (S1CON & 0x01)  {         /* RI*/
  27.       if (S1BUF == XOFF)  {
  28.         do  {
  29.           S1CON &= 0xFE;         /* RI = 0 */
  30.           while (!(S1CON & 0x01)); /* RI */
  31.         }
  32.         while (S1BUF != XON);
  33.         S1CON &= 0xFE;           /* RI = 0 */
  34.       }
  35.     }
  36.     while (!(S1CON & 0x02));     /* while (!TI); */
  37.     S1CON &= 0xFD;               /* TI = 0 */
  38.     S1BUF = 0x0d;                /* output CR  */
  39.   }
  40.   if (S1CON & 0x01)  {
  41.     if (S1BUF == XOFF)  {
  42.       do  {
  43.         S1CON &= 0xFE;           /* RI = 0 */
  44.         while (!(S1CON & 0x01)); /* while (!RI) */
  45.       }
  46.       while (S1BUF != XON);
  47.       S1CON &= 0xFE;             /* RI = 0 */
  48.     }
  49.   }
  50.   while (!(S1CON & 0x02));       /* while (!TI); */
  51.   S1CON &= 0xFD;                 /* TI = 0 */
  52.   return (S1BUF = c);
  53. }
  54.