We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have a strange problem in my code. I cannot receive correct characters via the serial port if I write TH1=0xFD in my code. But if I write TH1=0xFE in my code, I can run the program correctly.
Why?
Appreciate any response!
athena tsai
-----------------------------------
#include "reg51.h" #include "stdio.h"
void main (void) { SCON = 0x50;
TMOD |= 0x20;
TH1=0xFE; TR1=1; TI=1; while(1) { unsigned char aaa;
aaa=_getkey();
putchar(aaa); } }
Thans to Kalib Rahib's suggestion. My Xtal is 11.059MHz. I have modified my code and runing it OK!
I add a line in my code. PCON &= 0x7F; /* Clear SMOD bit -- This Bit double baud rate */ TH1=0xFD;
Here is my all code! -----------------------------------
TMOD |= 0x20; PCON &= 0x7F; TH1=0xFD; TR1=1; TI=1; while(1) { unsigned char aaa;