..#include<reg52.h>
#include<stdio.h>
unsigned char In_read_index_G;      // Data in buffer that has been read 
unsigned char In_waiting_index_G;   // Data in buffer not yet read
static void PC_LINK_IO_Send_Char(const char);
#define RECV_BUFFER_LENGTH 4
#define OSC_FREQ (11059200UL)
#define OSC_PER_INST (12)
static unsigned char Recv_buffer[RECV_BUFFER_LENGTH];

/*------------------------------------------------------------------*-

  PC_LINK_IO_Update()

  Checks for character in the UART (hardware) receive buffer
 
-*------------------------------------------------------------------*/
void PC_LINK_IO_Update(void)  
   {
    // Only dealing with received bytes here
   // -> Just check the RI flag
   if (RI == 1)
      {
      // Flag only set when a valid stop bit is received, 
      // -> data ready to be read into the received buffer

      // Want to read into index 0, if old data has been read
      // (simple ~circular buffer)
      if (In_waiting_index_G == In_read_index_G)
         { 
         In_waiting_index_G = 0;
         In_read_index_G = 0;
         } 
      
      // Read the data from UART buffer   
      Recv_buffer[In_waiting_index_G] = SBUF;

      if (In_waiting_index_G < RECV_BUFFER_LENGTH)
         {
         // Increment without overflowing buffer
         In_waiting_index_G++;
         }
    
      RI = 0;  // Clear RT flag
      }
   }

void PC_LINK_IO_Init_T1(const unsigned int BAUD_RATE)
   {
   PCON &= 0x7F;   // Set SMOD bit to 0 (don't double baud rates)

   //  Receiver enabled.
   //  8-bit data, 1 start bit, 1 stop bit, 
   //  Variable baud rate (asynchronous)
   //  Receive flag will only be set if a valid stop bit is received
   //  Set TI (transmit buffer is empty)
   SCON = 0x72;

   TMOD |= 0x20;   // T1 in mode 2, 8-bit auto reload

   TH1 = (256 - (unsigned char)((((unsigned long)OSC_FREQ / 100) * 3125) 
            / ((unsigned long) BAUD_RATE * OSC_PER_INST * 1000)));

   TL1 = TH1;  
   TR1 = 1;  // Run the timer
   TI = 1;   // Send first character (dummy)

   // Set up the buffers for reading and writing
   In_read_index_G = 0;
   In_waiting_index_G = 0;
   // Interrupt *NOT* enabled
   ES = 0;
   }

main()

{
unsigned char Ch;
unsigned int i,n1,n2,n;
PC_LINK_IO_Init_T1(9600);
i=0;
n1=0;
n2=0;
n=0;
while(1)
{
   PC_LINK_IO_Update();
if(In_waiting_index_G==4)
{
while(i<4)
{
if(i<2)
n1=n1*10+(unsigned int)(Recv_buffer[i]-'0');
if(i>=2)
n2=n2*10+(unsigned int)(Recv_buffer[i]-'0');
i++;
}
n=n1*(2*2*2*2)+n2;

P2=n;

i=0;
/*printf("%d",n);*/
In_waiting_index_G=0;
i=0;
n1=0;
n2=0;
n=0;
}
}//end of outer while
  
