I used the KEIL software to program the AT89C51ED2 chip, and I used the USB port to view the data transfer by PUTTY. But in the PUTTY, I can't get accurate information.
The code looks fine, the COM port is also set successfully, there was no problem with the connection of the circuit, but there has a problem in the display of putty.
In the PUTTY, according to ASCII. enter a should get b. but in here a got q, b got r, d got t, and GPRMC got w\SM{
is UART have the problem? or the timer? or other......
There are some code below here
#include<reg51.h> char uart_data; /** * FUNCTION_PURPOSE: This file set up uart in mode 1 (8 bits uart) with * timer 1 in mode 2 (8 bits auto reload timer). * FUNCTION_INPUTS: void * FUNCTION_OUTPUTS: void */ void main (void) { PCON=0; SCON = 0x50; /* uart in mode 1 (8 bit), REN=1 */ TMOD = 0x20 ; /* Timer 1 in mode 2 */ TH1 = 0xFD; /* 9600 Bds at 11.059MHz */ TL1 = TH1; /* 9600 Bds at 11.059MHz */ ES = 1; // Enable serial interrupt EA = 1; /* Enable global interrupt */ TR1 = 1; /* Timer 1 run */ while(1); /* endless */ } /** * FUNCTION_PURPOSE: serial interrupt, echo received data. * FUNCTION_INPUTS: P3.0(RXD) serial input * FUNCTION_OUTPUTS: P3.1(TXD) serial output */ void serial_IT(void) interrupt 4 { if (RI == 1) { /* if reception occur */ RI = 0; /* clear reception flag for next reception */ uart_data = SBUF; /* Read receive data */ SBUF = uart_data; /* Send back same data on uart*/ } else TI = 0; /* if emission occur */ } /* clear emission flag for next emission*/
"Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see:
learn.sparkfun.com/.../serial-communication
So how have you checked that your UART is really operating at the baud rate you think it is?
The easiest check is to transmit 'U' continuously, and look at the waveform on an oscilloscope.
Hello, Thank you for your prompt, I used the oscilloscope to view the U waveform. I was trying RX and TX pin. there have 8 square waves are displayed on the oscilloscope. But the last square wave occupies a wider range than before. when I try UU or UUUUU, there have 13 and 28 square waves, The last square wave also takes up more range than the previous square wave. Do you know why this happens?
Look again at that Sparkfun page: learn.sparkfun.com/.../serial-communication It shows you how to interpret the waveform ...
I looked at the waveform on the website, when I check waveform on my oscilloscope and given the time pressure.
is that despite that set the baud rate to 9600, i.e. the bit time should be 104 microseconds, the scope shows that the duration of each bit is ~4*104 us.
Even by changing the baud rate, the duration of the transmitted bits seem to remain the same...which is strange