uartc.c

来自「8051试验程序 基础教材」· C语言 代码 · 共 50 行

C
50
字号
//********************************************************************
//
// Author        : ADI - Apps            www.analog.com/MicroConverter
//
// Date          : 27 Jan 2004
//
// File          : uartc.c
//
// Hardware      : ADuC845, ADuC847, ADuC848
//
// Description   : Receives a character via the UART from Hyperterminal
//       and transmits back to Hyperterminal via the UART the
//       original entered character + 1 and +2.
//********************************************************************

#include <stdio.h>
#include <ioADuC845.h>  //To use the ADuC847 or ADuC848 simply change the header file to
                 //<ADuC847.h> or <ADuC848.h>

#define LED P3_bit.T0


void main (void)
{
   char  MyBuf;

   T3CON = 0x83;  //Configure UART for 9600 Baud rate
   T3FD = 0x12;
   SCON = 0x50;

   for(;;)
      {
      while (! SCON_bit.RI) {}      // Wait for character to be entered via Hyperterminal

      SCON_bit.RI = 0;         // Clear the RI interrupt
                  // Character is available in SBUF

      SBUF = SBUF+1;    // Transmit SBUF+1 via UART
      while(! SCON_bit.TI) {}          // Wait for completion of Tx

      SCON_bit.TI=0;         // Clear the Tx interrupt

      MyBuf = SBUF;        //
      SBUF = MyBuf+2;      // Transmit MyBuf+2 via UART
      while(! SCON_bit.TI) {}          // Wait for transmission completion
      SCON_bit.TI =0;         // Clear the interrupt
      }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?