1501697860 发表于 2013-8-17 16:11:07

有没人用STC写过PELCO-D协议485通信啊,帮我看看程序,问题出...

多谢了!麻烦看下.
#include <reg52.h>
#include<stdio.h>
#include<INTRINS.H>

#define Uchar unsigned char
#define Uintunsigned int
//sfr P4= 0xc0;
//sfr P4SW =0Xfe;
sbitLEFTEND=P2^2;//水平方向到达终点        为0是到了位置
sbitRIGHTEND=P2^3;//水平方向到达终点
sbitUPEND=P2^0;//向上走到了终点
sbitDOWNEND=P2^1;//向下走到了终点

sbitM1Switch=P0^0;   //为0是工作
sbitM2Switch=P0^1;
sbitM3Switch=P0^2;   //为0是工作
sbitM4Switch=P0^3;
sbitJ1Switch=P0^4;   //为0是工作
sbitJ2Switch=P0^5;        // 为0是工作
sbitPB2 = P1^2;   //遥控器输入   0工作
sbitPB3 = P1^3;   //遥控器输入   0工作
sbitPB1 = P1^1;   //遥控器输入   0工作
sbitPB0 = P1^0;   //遥控器输入       0工作
sbitRX= P3^0;
sbitTX= P3^1;

Uchar right, left, up, down;
Uchar   SHUIPINGPOINTER;
Uchar SHUZHIPOINTER;
Uchar P0BUF;
UintZIJIANNUM=800;//
UintRIGHTNUM;//自检时用来计算右转了几步
UintDOWNNUM;//自检时用来计下转了几步
UintSHUIPINGNUM;//水平方向所走的步数
UintSHUZHINUM;//竖直方向所走的步数
UintSHUIPINGSET;//水平方向应该走到的位置
UintSHUZHISET;//竖直方向应该走到的位置
UintSHUIPINGTOTALNUM;//5800
UintSHUZHITOTALNUM;//2200
Ucharheader_D;



Uchar Pelco_D = {0,0,0,0,0,0,0};

void Delay(Uint Num)        //延时
{
    Uchar i,j;
    while(--Num)
    for(j=0;j<2;j++)
        for(i=0;i<4;i++);
}






void main()
{
Uchar a;
P1=0Xff;        //所有的繼電器不工作
P2=0XFF;
P3=0X00;
P0=0X00;
   SCON = 0x50;      //REN=1允许串行接受状态,串口工作模式1                           
        TMOD|= 0x20;      //定时器工作方式2                  
        PCON|= 0x80;                                                         
        TH1 = 0xfa;        //波特率9600、数据位8、停止位1。效验位无 (11.0592M)
    TL1 = 0xfa;         
        TR1= 1;                                                            
        ES   = 1;      //开串口中断                  
        EA   = 1;      // 开总中断







while(1)
{
            P0=0X00;
        a=P1&0X0F;
       
   if(Pelco_D==0X00&&Pelco_D==0X0B&&Pelco_D==0X00&&Pelco_D==0X02&&Pelco_D==0X0E)       //右转
          {
   //灯光 FF01000B00020E
            //FF01000900020C
                  J2Switch = 1;
                  Delay(5);
               if(Pelco_D==0X00&&Pelco_D==0X09&&Pelco_D==0X00&&Pelco_D==0X02&&Pelco_D==0X0C)//停止工作
                     {
                                             J2Switch = 0;
                               }
           }
   if(Pelco_D==0X00&&Pelco_D==0X04&&Pelco_D==0X3F&&Pelco_D==0X00&&Pelco_D==0X04)       //右转
          {
                        M1Switch = 1;
                        M2Switch = 0;
                        Delay(5);
                   if(Pelco_D==0X00&&Pelco_D==0X00&&Pelco_D==0X00&&Pelco_D==0X00&&Pelco_D==0X01)//不工作
                     {
                                          M1Switch = 0;
                                     M2Switch = 0;
                       }
             //FF0100043F0044   
             //FF010000000001
           }
}
}

void ser_int (void) interrupt 4 using 1
{
Uchar i;
if(RI == 1)      //RI接受中断标志
{
for (i = 0; i<7; i++)//接收7次
    {
      Pelco_D= SBUF;
          Delay(1);
          if(i>=7)i=0;      
    }
        RI = 0; //清除RI接受中断标志

}
}

1501697860 发表于 2013-8-17 16:14:00

用485控制马达和灯,怎么控制啊,用的派尔高协议,头大啊.多谢了........

HeP028 发表于 2013-8-18 22:14:45

大部分市2400波特绿

1501697860 发表于 2013-8-19 07:44:29

HeP028 发表于 2013-8-18 22:14 static/image/common/back.gif
大部分市2400波特绿

多谢你的帮助

wkman 发表于 2013-8-19 08:39:12

1501697860 发表于 2013-8-17 16:14 static/image/common/back.gif
用485控制马达和灯,怎么控制啊,用的派尔高协议,头大啊.多谢了........

马达和灯?,不是用, DMX512 ,协议么?{:shocked:}
页: [1]
查看完整版本: 有没人用STC写过PELCO-D协议485通信啊,帮我看看程序,问题出...