|
|
Discussion Forum
Serial port Communication PC and AT89C52 ( continuted )
Next Thread | Thread List | Previous Thread
Start a Thread | Settings
| Details |
Message |
|
Read-Only
Author Justin Wong-
Posted 4-Dec-2004 02:21 GMT
Toolset C51
|
 Serial port Communication PC and AT89C52 ( continuted )
Justin Wong-
Here was my plan to realize the communication between PC and AT89C52, Both of them are set to 2400 (baud rate), N, 8, 1.
1. I have shortened pin 2 and pin 3 of RS-232 attached to PC. When my pc was sending out DATA, at the same time it can receive this DATA. After doing this, I found my PC can correctly receive the DATA just sent out.
2. The following is my C51 code. After receiving the incoming data, I want to show that data by LED connected to P1 port.
I thought my C51 code should be wrong, but I really have no idea……Please help me….
Sincere Thanks in advance.
unsigned char ISRIN;
unsigned char ISROUT;
unsigned char SERIALISRIN;
void DELAY ();
void INI_SERIAL();
unsigned char RECE_SERIAL ();
void main ()
{
unsigned char DATD;
P1 = 0xff;
INI_SERIAL();
While(1) {
if (ISRIN ) {
ISRIN = 0;
DATD = RECE_SERIAL ();
}
}
}
void SERIAL_ISR ( ) interrupt 4 using 1 (
if ( TI ) {
TI = 0 ;
ISROUT = 1;
}
if ( RI ) {
RI = 0;
ISRIN = 1;
}
}
void INI_SERIAL() {
EA = 0;
T2CON = 0x34;
RCAP2L = 0x64;
RCAP2H = 0xff;
TL2 = 0x64;
TH2 = 0xff;
SCON= 0x50;
TI = 0;
RI = 0;
TR2 = 1;
ES= 1;
EA =1;
}
unsigned char RECE_SERIAL () {
unsigned char DAT;
P1 = SBUF;
DAT = P1;
DELAY ();
P1 = 0xff;
return DAT;
}
|
|
|
Read-Only
Author Andrew Neil
Posted 4-Dec-2004 10:52 GMT
Toolset C51
|
 RE: Serial port Communication PC and AT89C52 ( continuted )
Andrew Neil
Why are you starting a new thread?
Please re-post your code, and follow the instructions this time: there are 3 bullet points above the "Message" window when you post - the 3rd one tells you what to do with source code.
There is also a link to Tips for Posting Messages:
http://www.keil.com/forum/tips.asp
|
|
|
Read-Only
Author Justin Wong
Posted 5-Dec-2004 04:11 GMT
Toolset C51
|
 RE: Serial port Communication PC and AT89C52 ( continuted )
Justin Wong
Here was my plan to realize the communication between PC and AT89C52, Both of them are set to 2400 (baud rate), N, 8, 1.
1. I have shortened pin 2 and pin 3 of RS-232 attached to PC. When my pc was sending out DATA, at the same time it can receive this DATA. After doing this, I found my PC can correctly receive the DATA just sent out.
2. The following is my C51 code. After receiving the incoming data, I want to show that data by LED connected to P1 port.
I thought my C51 code should be wrong, but I really have no idea……Please help me….
Sincere Thanks in advance.
unsigned char ISRIN;
unsigned char ISROUT;
unsigned char SERIALISRIN;
void DELAY ();
void INI_SERIAL();
unsigned char RECE_SERIAL ();
void main ()
{
unsigned char DATD;
P1 = 0xff;
INI_SERIAL();
While(1) {
if (ISRIN ) {
ISRIN = 0;
DATD = RECE_SERIAL ();
}
}
}
void SERIAL_ISR ( ) interrupt 4 using 1 (
if ( TI ) {
TI = 0 ;
ISROUT = 1;
}
if ( RI ) {
RI = 0;
ISRIN = 1;
}
}
void INI_SERIAL() {
EA = 0;
T2CON = 0x34;
RCAP2L = 0x64;
RCAP2H = 0xff;
TL2 = 0x64;
TH2 = 0xff;
SCON= 0x50;
TI = 0;
RI = 0;
TR2 = 1;
ES= 1;
EA =1;
}
unsigned char RECE_SERIAL () {
unsigned char DAT;
P1 = SBUF;
DAT = P1;
DELAY ();
P1 = 0xff;
return DAT;
} .
|
|
|
Read-Only
Author Justin Wong
Posted 5-Dec-2004 04:29 GMT
Toolset C51
|
 RE: Serial port Communication PC and AT89C52 ( continuted )
Justin Wong
By the way,how to select AT89C52 Timer 2 Serial Clock Divisor? right now, I am sure my MCU is working correctly for receiving and sending out the data ( I did this under a friend's suggestion ). SO I thought the Serial Clock Divisor of AT89C52 is wrong.
Would you help me to check it?
Thank you.
|
|
|
Read-Only
Author Andrew Neil
Posted 6-Dec-2004 00:38 GMT
Toolset C51
|
 RE: Serial port Communication PC and AT89C52 ( continuted )
Andrew Neil
OK, now you've got the 'pre' and '/pre' tags sussed, the whole point of using them is to preserve the layout of your code!
Please go back to your original, formmatted code and post that between 'pre' and '/pre' tags.
For example,void main ()
{
unsigned char DATD;
P1 = 0xff;
INI_SERIAL();
While(1) {
if (ISRIN ) {
ISRIN = 0;
DATD = RECE_SERIAL ();
}
}
}
Remember: don't use TABs; use only spaces for layout.
|
|
Next Thread | Thread List | Previous Thread
Start a Thread | Settings
|
|
|