51单片机串口双机通讯出问题了。求大神帮助~!
时间:10-02
整理:3721RD
点击:
2个51单片机的RXD 和TXD 直接连接。(1机的RXD接2机的TXD。1机的TXD接2机的RXD。)程序用的课本的程序。可是就是通讯不成功。
1机程序void send(uchar state)
{
SBUF=state;
while(TI==0);
TI=0;
}
void SCON_int(void)
{
SCON=0X40;
TMOD=0X20;
PCON=0X00;
TH1=0XFD;
TL1=0XFD;
TI=0;
TR1=1;
}
void main()
{
SCON_int();
while(1)
{
send(P1);
}
}
2机uchar state;
void receive()
{
while(RI==0);
state=SBUF;
RI=0;
}
void SCON_int(void)
{
SCON=0X50;
TMOD=0X20;
PCON=0X00;
TH1=0XFD;
TL1=0XFD;
RI=0;
TR1=1;
}
void main()
{
SCON_int();
while(1)
{
receive();
P1=state;
}
}
哪有有错,求指点
1机程序void send(uchar state)
{
SBUF=state;
while(TI==0);
TI=0;
}
void SCON_int(void)
{
SCON=0X40;
TMOD=0X20;
PCON=0X00;
TH1=0XFD;
TL1=0XFD;
TI=0;
TR1=1;
}
void main()
{
SCON_int();
while(1)
{
send(P1);
}
}
2机uchar state;
void receive()
{
while(RI==0);
state=SBUF;
RI=0;
}
void SCON_int(void)
{
SCON=0X50;
TMOD=0X20;
PCON=0X00;
TH1=0XFD;
TL1=0XFD;
RI=0;
TR1=1;
}
void main()
{
SCON_int();
while(1)
{
receive();
P1=state;
}
}
哪有有错,求指点