title: Why It is stuck in loop? RX pin is not receiving data from Virtual Terminal?
body: <p>This code is to simulate RFID reader working using AT89C51 in Proteus Software. Instead of RFID reader i am using Virtual Terminal for sending or scanning RFID, here in my case I am Typing ID in Virtual Terminal,
  string  'a' stores input and compares with existing string and gives Output.
  Problem here is the ID I am typing in virtual terminal is not copied to string 'a'.
  It is stuck in while loop. RI is a interrupt flag that tells if any serial data received in RX pin.</p>
  <pre><code>//CODE of lcd interfacing with 8051 microcontroller
  #include&lt;reg51.h&gt;
  #include&lt;string.h&gt;
  
  void delay( unsigned int i );
  void lcd_cmd( unsigned char a );
  void lcd_data( unsigned char b );
  void lcd_init( void );
  void lcd_str( unsigned char* str );
  void sendser_char( unsigned char b );
  void sendser_str( unsigned char* str );
  sbit rs = P2 ^ 0;
  sbit en = P2 ^ 1;
  unsigned int i;
  unsigned char a[60], b[10];
  sfr ldata = 0x90;//port1 
  void clear( void );
  
  void main()
  {
      TMOD = 0x20;//timer1 mode2 -auto reload mode
      TH1 = 0xfd;//9600 baud rate
      SCON = 0x50;//8bit data ,1start bit,1stop bit
      TR1 = 1;
      REN = 1;
      lcd_init();
      lcd_str( &quot;   WELCOME TO   &quot; );
      lcd_cmd( 0xc0 );
      lcd_str( &quot;   MY PROJECT   &quot; );
  
      delay( 65000 );
      while( 1 )
      {
          lcd_cmd( 0x01 );
          lcd_cmd( 0x80 );
          lcd_str( &quot;   Waiting For    &quot; );
          delay( 65000 );
          lcd_cmd( 0xc0 );
          lcd_str( &quot;   RFID Tag   &quot; );
          delay( 65000 );
  
          for( i = 0; i &lt; 10; i++ )
          {
              while( RI == 0 );   //code is stuck here, RI value shall be changed 
                              //when input given in virtual terminal.but it is never changing.
              a[i] = SBUF;
              RI = 0;
          }
          a[i] = '\0';
          delay( 65000 );
          if( 0 == strcmp( &quot;0123456789&quot;, a ) )
          {
              lcd_cmd( 0x01 );
              lcd_cmd( 0x80 );
              lcd_str( &quot; WELCOME USER 1&quot; );
              lcd_cmd( 0xc0 );
              lcd_str( a );
              delay( 65000 );
              clear();
          }
          else if( 0 == strcmp( &quot;10003B0CAE&quot;, a ) )
          {
              lcd_cmd( 0x01 );
              lcd_cmd( 0x80 );
              lcd_str( &quot; WELCOME USER 2&quot; );
              lcd_cmd( 0xc0 );
              lcd_str( a );
              delay( 65000 );
              clear();
          }
          else
          {
              lcd_cmd( 0x01 );
              lcd_cmd( 0x80 );
              lcd_str( &quot; INVALID TAG&quot; );
              lcd_cmd( 0xc0 );
              lcd_str( a );
              delay( 65000 );
              clear();
          }
      }
  }
  
  void lcd_init()
  {
      lcd_cmd( 0x38 );
      lcd_cmd( 0x0c );
      lcd_cmd( 0x01 );
      lcd_cmd( 0x80 );
  }
  
  void delay( unsigned int i )
  {
      unsigned int j;
      for( j = 0; j &lt; i; j++ );
  }
  
  void lcd_cmd( unsigned char a )
  {
      rs = 0;//cmd 
      ldata = a;
      en = 1;
      delay( 5 );
      en = 0;
      delay( 5 );
  }
  
  void lcd_data( unsigned char b )
  {
      rs = 1;//data 
      ldata = b;
      en = 1;
      delay( 5 );
      en = 0;
      delay( 5 );
  }
  
  void lcd_str( unsigned char* str )
  {
      while( *str )
      {
          lcd_data( *str++ );
      }
  }
  
  void sendser_char( unsigned char b )
  {
      SBUF = b;
      while( TI == 0 );
      TI = 0;
  }
  
  void sendser_str( unsigned char* str )
  {
      while( *str )
      {
          sendser_char( *str++ );
      }
  }
  
  void clear( void )
  {
      unsigned int i;
      for( i = 0; i &lt; 60; i++ )
      {
          a[i] = '\0';
      }
  }
  </code></pre>