This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

8051 serial port

i want to set the baud rate of AT89S52 to 9600 to connect to a wireless module that work on the same baud rate . The output should be any number from 1 to 9. This is my code for the serial port, but using it gives a wrong output on the hyper terminal ex if no. 1 is pressed the putput is 81818181818181..... If anyone could help to figure out the problem?

void UART_Init()
{ TMOD |=0x20; //Timer1 in Mode2.
TH1= 0xE6; // 9600 Baud rate at 12MHz
SCON=0x50; // Asynchronous mode 8-bit data and 1-stop bit
TR1=1; //Turn ON the timer.
TI=1; // TI: set TI to send first char of UART

}
void UART_Tx(int ch)
{ SBUF=ch; // Load the data to be transmitted
while(TI==0); // Wait till the data is trasmitted
TI=0; //Clear the flag for next cycle. }

Thank you in advance.

0