⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 finger.c

📁 MSP430设计的继电保护控制和通信程序
💻 C
📖 第 1 页 / 共 5 页
字号:
        } 
    }
    if(Time_count==0)
    return ComErr;
    else
    {
      if(RecComm[21] == CheckSum(RecComm,21))
      {
         for(m=0;m<4;m++)
         {
               BitCode32[m]=RecComm[m+1];
         }
         for(m=0;m<8;m++)
         {
                ConfigPass1[m]=RecComm[m+5];
         }
         for(m=0;m<8;m++)
         {
                ConfigPass2[m]=RecComm[m+13];
         }
         if((config_flag==1)&&((RecComm[0]==0x01)||(RecComm[0]==0x02)))  /* 用于第一次配置密码 */
         {
            BackErr=0x00;       //正确
            config_flag=0;         //清除32bit配置条码 标志    
            copy(pBitCode32,BitCode32,4);
            copy(pConfigPass1,ConfigPass1,8);
            copy(pConfigPass2,ConfigPass2,8);
            copy(PrivateUnlockPass,ConfigPass1,6);   
            flash_write((char *)0x01000,BitCode32,4);
            flash_write((char *)0x01004,ConfigPass1,8);
            flash_write((char *)0x0100c,ConfigPass2,8);
            flash_write((char *)0x01016,&config_flag,1);//保存条码标志 
            flash_write((char *)0x01070,PrivateUnlockPass,6);
        }
         if((config_flag==0)&&((RecComm[0]==0x01)||(RecComm[0]==0x02)))   /* 用于更改密码 */
         {    
            if(Verify(BitCode32,pBitCode32,4)==RIGHT)
            {
               BackErr=0x00;
               copy(pConfigPass1,ConfigPass1,8);
               copy(pConfigPass2,ConfigPass2,8);
               flash_write((char *)0x01004,pConfigPass1,8);
               flash_write((char *)0x0100c,pConfigPass2,8);
               Master_Slave(0x01);                 //配置Slave板
            }
            else BackErr=0x02;              // 返回条码错误
         }
     }
     else BackErr=0x01;                       //校验马错误   
     for(m=0;m<21;m++)
     {
            BackData[m]=RecComm[m];
     }
     BackData[21]=BackErr;      //填充状态字节
     BackData[22]=CheckSum(BackData,22);
     SendFrame(BackData,23);        //向上微机返回数据
     return BackErr;
   }
}       
/////////////////////////////主板与执行板通讯模块
uchar Master_Slave(uchar Comm)  //Comm 0x01 is save comm, 0x02 is verity and Unlock
{
     uchar CommArr[18];
     P5DIR |= BIT4;
     P5OUT |= BIT4;
     //SetSEL0;
     delay(500);
     
     CCTL0 &= ~CCIE;                        //关定时器中断
     RecCount=0;
     FrameCount=2;
     CommArr[0]=Comm;
     copy(&CommArr[1],pConfigPass1,8);
     copy(&CommArr[9],pConfigPass2,8);
     CommArr[17]=CheckSum(CommArr,17);
     SendFrame(CommArr,18);
     Time_count=20;
     while((RecCount != FrameCount)&&(Time_count>0))
     {
        if(TACTL & TAIFG)
        {
           Time_count--;
           TACTL &= ~TAIFG;  //轻重断标志
        } 
     }
     P5DIR |= BIT4;
     P5OUT &= ~BIT4;
     delay(500);
     if(Time_count == 0)
     return ComErr;
     else
     return RecComm[1];
}
//////////////////////////////
uchar CMDIsRootMaster()     
{
   uchar *pComm;
   P5DIR |= BIT4;
   P5OUT &= ~BIT4;
   delay(500);
   RecCount=0;
   FrameCount =12;
   pComm = CMD_IS_ROOT_MASTER;
   *(pComm + 11)= CheckSum(pComm,11);
   SendFrame(pComm,12);
   CCTL0 &= ~CCIE;                         // CCR0 interrupt disable
   Time_count=50;
    while((RecCount != FrameCount)&&(Time_count>0))     //20s等待通讯
    {
        if(TACTL & TAIFG)
        {
           Time_count--;
           TACTL &= ~TAIFG;  //轻重断标志
        } 
    }
    if(Time_count==0)
    return ComErr;
   else
   {
      if (RecComm[11]!=CheckSum(RecComm,11)) return CheckSumErr;
      else 
      {  
           Param1_L=RecComm[2];
           Param1_H=RecComm[3];
           Param2_L=RecComm[4];
           Param2_H=RecComm[5];
           return RecComm[10];
      }
   }
}
//////////////////////////////
uchar CMDDeviceTest()  
{
   uchar *pComm;
   P5DIR |= BIT4;
   P5OUT &= ~BIT4;
   delay(500);
   RecCount=0;
   FrameCount =12;
   pComm = CMD_DEVICE_TEST;
   *(pComm + 11)= CheckSum(pComm,11);
   SendFrame(pComm,12);
   CCTL0 &= ~CCIE;                         // CCR0 interrupt disable
   Time_count=50;
   while((RecCount != FrameCount)&&(Time_count>0))     //5s等待通讯
    {
        if(TACTL & TAIFG)
        {
           Time_count--;
           TACTL &= ~TAIFG;  //轻重断标志
        } 
    }
    if(Time_count==0)
    return ComErr;
    else
    {
       if (RecComm[11]!=CheckSum(RecComm,11)) return CheckSumErr;
       else 
      {  
           Param1_L=RecComm[2];
           Param1_H=RecComm[3];
           Param2_L=RecComm[4];
           Param2_H=RecComm[5];
           return RecComm[10];
      }
    }
}
//////////////////////////////////////
uchar CMDSetSystemInfo(uchar Param2L,uchar Param2H)    
{
   uchar *pComm;
   P5DIR |= BIT4;
   P5OUT &= ~BIT4;
   delay(500);
   RecCount=0;
   FrameCount =12;
   pComm = CMD_SET_SYSTEM_INFO;
   *(pComm+4)=Param2L;
   *(pComm+5)=Param2H;
   *(pComm + 11)= CheckSum(pComm,11);
   SendFrame(pComm,12);
   Time_count=50;
    while((RecCount != FrameCount)&&(Time_count>0))     //5s等待通讯
    {
        if(TACTL & TAIFG)
        {
           Time_count--;
           TACTL &= ~TAIFG;  //轻重断标志
        } 
    }
    if(Time_count==0)
    return ComErr;
   else
   {
      if (RecComm[11]!=CheckSum(RecComm,11)) return CheckSumErr;
      else 
      {  
           Param1_L=RecComm[2];
           Param1_H=RecComm[3];
           Param2_L=RecComm[4];
           Param2_H=RecComm[5];
           return RecComm[10];
      }
    }
}
////////////////////////
uchar CMDGetSystemInfo()
{
   uchar *pComm;
   P5DIR |= BIT4;
   P5OUT &= ~BIT4;
   delay(500);
   RecCount=0;
   FrameCount =12;
   pComm = CMD_GET_SYSTEM_INFO;
   //*(pComm+4)=Param2L;
   //*(pComm+5)=Param2H;
   *(pComm + 11)= CheckSum(pComm,11);
   SendFrame(pComm,12);
   Time_count=50;
    while((RecCount != FrameCount)&&(Time_count>0))     //20s等待通讯
    {
        if(TACTL & TAIFG)
        {
           Time_count--;
           TACTL &= ~TAIFG;  //轻重断标志
        } 
    }
    if(Time_count==0)
    return ComErr;
   else
   {
      if (RecComm[11]!=CheckSum(RecComm,11)) return CheckSumErr;
      else 
      {
         
           Param1_L=RecComm[2];
           Param1_H=RecComm[3];
           Param2_L=RecComm[4];
           Param2_H=RecComm[5];
           return RecComm[10];
     
       }
    }
}
///////////////////////
uchar CMDGetRecCount()     //还应该加入接受等待延时6秒
{
   uchar *pComm;
   P5DIR |= BIT4;
   P5OUT &= ~BIT4;
   delay(500);
   RecCount=0;
   FrameCount =12;
   pComm = CMD_GET_REC_COUNT;
   *(pComm + 11)= CheckSum(pComm,11);
   SendFrame(pComm,12);
   Time_count=50;
    while((RecCount != FrameCount)&&(Time_count>0))     //20s等待通讯
    {
        if(TACTL & TAIFG)
        {
           Time_count--;
           TACTL &= ~TAIFG;  //轻重断标志
        } 
    }
    if(Time_count==0)
    return ComErr;
   else
   {
       if (RecComm[11]!=CheckSum(RecComm,11)) return CheckSumErr;
       else 
       {  
           Param1_L=RecComm[2];
           Param1_H=RecComm[3];
           Param2_L=RecComm[4];
           Param2_H=RecComm[5];
           return RecComm[10];
      }
   }
}     
////////////////////////////////////////
uchar CMDGetMasterCount()     
{
   uchar *pComm;
   P5DIR |= BIT4;
   P5OUT &= ~BIT4;
   delay(500);
   RecCount=0;
   FrameCount =12;
   pComm = CMD_GET_MASTER_COUNT;
   *(pComm + 11)= CheckSum(pComm,11);
   SendFrame(pComm,12);
   Time_count=50;
    while((RecCount != FrameCount)&&(Time_count>0))     //20s等待通讯
    {
        if(TACTL & TAIFG)
        {
           Time_count--;
           TACTL &= ~TAIFG;  //轻重断标志
        } 
    }
    if(Time_count==0)
    return ComErr;
   else
   {
       if (RecComm[11]!=CheckSum(RecComm,11)) return CheckSumErr;
       else 
       {  
           Param1_L=RecComm[2];
           Param1_H=RecComm[3];
           Param2_L=RecComm[4];
           Param2_H=RecComm[5];
           return RecComm[10];
      }
   }
}     
/////////////////////////////
uchar CMDFpRegisterStart(uchar Param1L,uchar Param1H,uchar Param2L,uchar Param2H)
{
   uchar *pComm;
   P5DIR |= BIT4;
   P5OUT &= ~BIT4;
   delay(500);
   RecCount=0;
   FrameCount =12;
   pComm = CMD_FP_REGISTER_START;
   *(pComm + 2) = Param1L;
   *(pComm + 3) = Param1H;
   *(pComm + 4) = Param2L;
   *(pComm + 5) = Param2H;
   *(pComm + 11)= CheckSum(pComm,11);
   SendFrame(pComm,12);
   Time_count=70;
   while((RecCount != FrameCount)&&(Time_count>0))     //7s等待通讯
   {
        if(TACTL & TAIFG)
        {
           Time_count--;
           TACTL &= ~TAIFG;  //轻重断标志
        } 
    }
   if(Time_count == 0)
   return ComErr;
   else
   {
       if (RecComm[11]!=CheckSum(RecComm,11)) return CheckSumErr;
       else 
       {  
           Param1_L=RecComm[2];
           Param1_H=RecComm[3];
           Param2_L=RecComm[4];
           Param2_H=RecComm[5];
           return RecComm[10];
      }
    }
}     
////////////////////////////////
uchar CMDFpRegisterEnd(uchar Param1L,uchar Param1H,uchar Param2L,uchar Param2H)
{
   uchar *pComm;
   P5DIR |= BIT4;
   P5OUT &= ~BIT4;
   delay(500);
   RecCount=0;
   FrameCount =12;
   pComm = CMD_FP_REGISTER_END;
   *(pComm + 2) = Param1L;
   *(pComm + 3) = Param1H;
   *(pComm + 4) = Param2L;
   *(pComm + 5) = Param2H;
   *(pComm + 11)= CheckSum(pComm,11);
   SendFrame(pComm,12);
   Time_count=70;
   while((RecCount != FrameCount)&&(Time_count>0))     //6s等待通讯
   {
        if(TACTL & TAIFG)
        {
           Time_count--;
           TACTL &= ~TAIFG;  //轻重断标志
        } 
    }
   if(Time_count == 0)
   return ComErr;
   else
   {
       if (RecComm[11]!=CheckSum(RecComm,11)) return CheckSumErr;
       else 
       {  
           Param1_L=RecComm[2];
           Param1_H=RecComm[3];
           Param2_L=RecComm[4];
           Param2_H=RecComm[5];
           return RecComm[10];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -