登录
首页 现场总线
回帖 发帖
正文

主题:RS485点对点通讯,为什么小灯不亮?有图有码

点击:1417 回复:0

为什么上位机和下位机的小灯都没有亮?
上位机程序:
[code]
#include
#include
#define uchar unsigned char
#define _RDY_    0x06
#define _OK_    0x00
uchar tmp;
sbit M_DE = P1^0;
sbit M_RE = P1^1;
void initSerial()
{
   TMOD = 0x20;
   TH1 = 250;
   TL1 = 250;
   TR1 = 1;
   PCON = 0x80;
   SCON = 0x50;
}
void main (void)
{
   uchar LED;
   initSerial();
   EA = 0;
   
   M_DE = 1;        //置发送允许,接收禁止
   M_RE = 1;
   
   TI = 0;
   SBUF = _RDY_;
   while(!TI)
   TI = 0;
   while(tmp != _OK_)
   {
       RI = 0;
       while(!RI);
       tmp = SBUF;
       RI = 0;
   }
   while(1)
   {
       LED = 0xfe;
       P0 = LED;
   }        
}
[/code]
下位机程序:
[code]
#include
#include
#define uchar unsigned char
#define _RDY_    0x06
#define _OK_    0x00
uchar tmp;
sbit M_DE = P1^0;
sbit M_RE = P1^1;
void initSerial()
{
   TMOD = 0x20;
   TH1 = 250;
   TL1 = 250;
   TR1 = 1;
   PCON = 0x80;
   SCON = 0x50;
}
void main (void)
{
   uchar LED;
   initSerial();
   EA = 0;
   
   M_DE = 0;        //置接收允许,发送禁止
   M_RE = 0;
   
   while(1)
   {
       while(tmp != _RDY_)
       {
           RI = 0;
           while(!RI);
           tmp = SBUF;
           RI = 0;
       }
       TI = 0;
       SBUF = _OK_;
       while(!TI);
       TI = 0;
       while(1)
       {
           LED = 0xfe;
           P0 = LED;
       }
   }        
}
[/code]
附件
06-11-24 17:38

工控新闻

更多新闻资讯