Embedded C help with RS 232 COM1

Thread Starter

indianhits

Joined Jul 25, 2009
86
Hello guys i need help with this code.


Rich (BB code):
#include <AT89X55.H>


unsigned char ch='A';


void serial_init()
{
    SCON=0x50;
    TMOD=0x20;
    TH1=0xFD;
    TR1=1;
    TI=1;
}



void main()  
{
    serial_init();
    while(1)
    {
      SBUF=ch;
      TI=1;
      while(TI==0);
      TI=0;      
    }

}
Basically i want to echo the letter 'A' in HyperTerminal but all i get is this


Please help me.Thanks!
 

Papabravo

Joined Feb 24, 2006
21,225
I see by the register names that you are using an 8051 or derivative part. What baudrate is the 8051 at and how did you determine that? What baudrate is Hyperterm at? At a minimum they need to be the same.

In order to determine the baudrate I need a link to the datasheet for your specific part and I need to know the oscillator frequency.
 

Thread Starter

indianhits

Joined Jul 25, 2009
86
i am using ATMEL AT89S52 with 11.0592MHZ with baud rate 9600,no parity,1 stop bit and start bit.But still can you tell me if there is anything wrong in the code

Thanks!
 

Papabravo

Joined Feb 24, 2006
21,225
I think that what is wrong might start with how the baudrate for the UART is being generated.
You are not supposed to set the TI bit to a one. In the code you wrote you will never wait for the character to be transmitted because TI will never be 0 when you execute the inner while loop. You need to go back and read the datasheet again.
 
Top