Here is my intiat program for 82C51 (UART) but it is not working. So need help

From: M.Tekeste_at_Bradford.ac.uk <(M.Tekeste_at_Bradford.ac.uk)>
Date: Wed May 9 14:34:14 2001

#include <conio.h>
#include <stdio.h>
#include <dos.h>

/* Type Definitions */

typedef unsigned char UBYTE; /* Old habbit... */

/* Serial Port Definitions */

#define STATUS 0x308 /* Status Base Address */
#define CONTROL 0x300 /* Control Base Address */
#define TXREG 0x30C /* Transmit Base Address */
#define RXREG 0x304 /* Receive Base Address */
#define TRUE 1

/* Function Prototypes */

void InitUSART(void); /* Initialize USART */
void TxData(UBYTE); /* Transmit Data */
UBYTE RxData(void); /* Receive Data */

/*
   InitUSART() - Initialize USART to 153600, 8 Data Bits, No Parity, 1
Stop
Bit
*/
void InitUSART(void)
{
  outp(CONTROL, 0x00);
  outp(CONTROL, 0x00);
  outp(CONTROL, 0x00);
  outp(CONTROL, 0x40); // Reset UART
  outp(CONTROL, 0x4E); // Stop, no parity, 8-bit, %16 baud
  outp(CONTROL, 0x05); // UART now ready
}

/*
   TxData() - Send Data to Serial Port
   Entry:
      data = Data to transmit
*/
void TxData(UBYTE data)
{
  UBYTE x;

  /* Check for Tx Buffer Empty */
  do
  {
    x = inp(STATUS);
    x &= 0x01;
  } while(x == 0);

  outp(TXREG, data); /* Send Data */
}

/*
   RxData() - Receive Data from the Serial Port
   Exit:
      data = Rx Data byte
*/
UBYTE RxData(void)
{
  UBYTE x;
  UBYTE data = 0;

 while(TRUE) /* Check for Rx Data */
  {
    x = inp(STATUS);
    x &= 0x02;
    if(x == 0x02)
    {
      data = inp(RXREG); /* Get Data */
      break;
    }

    /* Optional. Aborts if keypress */

    if(kbhit()) /* Abort if Keypress */
    {
      getch();
      printf("\n");
      break;
    }
  }
  return(data);
}


void main(void)
{
UBYTE DSR;

InitUSART();

while(TRUE)
  putch(RxData());
}
Received on Wed May 09 2001 - 14:34:14 BST

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:34:07 BST