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); } }
What MHz do your crystal be? And what processor do the board having? And does the processor have a double baudrate bit in the SFR?
Ansewr these simple questions and put the values into your spread sheet and you will know the solution.
Ah Kalib Rahib, welcome back! It has been a long time!
Yes I am being back :)
At the last Sir Erak was angry and I had to be standing in the corner with my hat on for a long time ;)
Ho don't worry Kalib, sir Erak is only mad at one specific individual (you know his nickname...).
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;