Embedded C help with RS 232 COM1

Discussion in 'Programmer's Corner' started by indianhits, Mar 25, 2010.

  1. indianhits

    Thread Starter Active Member

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


    Code ( (Unknown Language)):
    1.  
    2. #include <AT89X55.H>
    3.  
    4.  
    5. unsigned char ch='A';
    6.  
    7.  
    8. void serial_init()
    9. {
    10.     SCON=0x50;
    11.     TMOD=0x20;
    12.     TH1=0xFD;
    13.     TR1=1;
    14.     TI=1;
    15. }
    16.  
    17.  
    18.  
    19. void main()  
    20. {
    21.     serial_init();
    22.     while(1)
    23.     {
    24.       SBUF=ch;
    25.       TI=1;
    26.       while(TI==0);
    27.       TI=0;      
    28.     }
    29.  
    30. }
    31.  
    Basically i want to echo the letter 'A' in HyperTerminal but all i get is this
    [​IMG]

    Please help me.Thanks!
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,164
    1,797
    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.
     
  3. indianhits

    Thread Starter Active Member

    Jul 25, 2009
    86
    0
    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!
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,164
    1,797
    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.
     
  5. indianhits

    Thread Starter Active Member

    Jul 25, 2009
    86
    0
    Thanks for reply got it right
     
Loading...