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

📄 tcpip.c

📁 这是本人以前用C51做的TCP/IP协议,也是借鉴了一些前辈的东西,,,,绝对可用!
💻 C
📖 第 1 页 / 共 5 页
字号:
         RI=0;
         break;
        }
    }
 _nop_();
}


/////////
void quiterror(void)
{_nop_();
snd1char(0xaa);
 _nop_();
 snd1char(0x55);
 snd1char(0x88);

 en489=0;
 SM2=1;
 EA=1;
}
void quitok(void)
{_nop_();
snd1char(0xaa);
 _nop_();
 snd1char(0x55);
 snd1char(0x33);

 en489=0;
 SM2=1;
 EA=1;
}
/////////////////serial interupt**********************
void serialint(void) interrupt 4 using 3
{uchar data ir,tempj[3]={0};
  EA=0;
  for(ir=0;ir<1;ir++)
//address//
  {
    get1char();
      if(riflag==0)
         {//quiterror();
         en489=0;
         SM2=1;
         EA=1;
         return;
         }
      tempj[0]=SBUF;

  }
   // tempj[1]=0xb0 ;  //(XBYTE[cs5_add245]&0x0f|0xb0);
    tempj[1]=(XBYTE[add245]&0x0f|0xb0)  ;
  if (tempj[0]!=tempj[1])//(XBYTE[cs5_add245]&0x0f|0xb0))  ;////0x00)  compare address =b0?
    {_nop_();//quiterror();
     en489=0;
     SM2=1;
     EA=1;
     return;
    }
    _nop_();
 //   SBUF=0X77;
 //while(1)      //////test
 //SM2=0;  //NEW
  snd1char(0xaa);   //snd1char(0xaa);tichar(0x88);
  _nop_();
  snd1char(0x55);

  snd1char(tempj[0]); //send back address ;b0;
  en489=0;
  SM2=0;
  get1char();
  if (riflag==0)
     {quiterror();
     return;
     }
  tempj[0]=SBUF;

   switch(tempj[0])
         {case 0xf0: set_time();break;
          case 0xf1: receive_sch();break;
          case 0xf2: get_pausef();break;
          case 0xf3: get_resume();break;
          case 0xf5: lostpow_set();break;
          case 0xf6: send_realdat();break;
          case 0xf7: receive_kbv();break;
          case 0xf8: sendback_kbv();break;
         case 0xf9: get_2da();        break;
         case 0xfa: locate_start();   break;
         case 0xfb: begin_test();     break;
         case 0xfc: send_calidat();   break;

          default: break;
         }
//quitok();
}
//
void sendback_kbv(void)     //F7
{uint ib;
 // uchar data temp[4]={0};
 _nop_();
 snd1char(0xaa);
 _nop_();
 snd1char(0x55);
  for(ib=0;ib<1350;ib++)          //(send_sum)
      {
       snd1char(kbbufa(ib));
      }
  if(kbbuf(1)==0x08)
       caliwrfg8=0;
  pccomutm=0;       //for pc
  quitok();                    //fail,  back aa,55 ,88
  return;
}
void receive_kbv(void)     //F2  hui jian 48*10+20+4 =504
{uint ib;
  for(ib=0;ib<1350;ib++)     //he 4 bytes    1+1+1344+4
       { get1char();
          if (riflag!=1)
          {quiterror();
          return;
          }
         kbbuf(ib)=SBUF; // READ SBUF
        }
      //
 /* count2=0;
  temp1bytex=0;
  temp1bytey=0;
  for(ic=0;ic<500;ic++) //count1-4
         {_nop_();
          count2=count2+kbbuf[ic]; //temp1bytex ;//count2+recibuf[i+2] ;
         }
  temp1bytey=count2;

 temp1bytex=kbbuf[ic];
 count1=temp1bytex;

 temp1bytex=kbbuf[ic+1];
 temp1bytex<<=8;
 count1+=temp1bytex;

 temp1bytex=kbbuf[ic+2];
 temp1bytex<<=16;
 count1+=temp1bytex;

  temp1bytez=count1;
  if (count1==count2)//(count1==count2)  */
         caliwrfg=kbbuf(1);      //cali flag;  zone num.
         caliwrfg8=1;
          quitok();
          return;     //get sch success,  back aa,55 ,33

  // quiterror();      //fail,  back aa,55 ,88
  // return;
}
void lostpow_set(void)     //F5
{uint ic;
  for(ic=0;ic<1;ic++)
       { get1char();
          if (riflag!=1)
          {quiterror();
          return;                     // 01 huifu  ,05 clr
          }
         plostway=SBUF; // READ SBUF
       }

  quitok();
  return;     //get sch success,  back aa,55 ,33


}
void get_pausef(void)     //F3
{ uint ic,lm;
 // uchar iz,ih;
  for(ic=0;ic<4;ic++)
       { get1char();
          if (riflag!=1)
          {quiterror();
          return;
          }
         dst_buf[ic]=SBUF; // READ SBUF
       }
  ic=dst_buf[1];
  ic<<=8;
  ic+=dst_buf[0];
  ic&=0x03f;              //begin cell
  //iz=(dst_buf[0]/16)&0x03 ;  //zone
  //ih=(dst_buf[0]%16)&0x0f ;  //ch


  lm=dst_buf[3];
  lm<<=8;
  lm+=dst_buf[2];
  lm&=0x03f;
  lm+=ic;
  if((dst_buf[3]&0xc0)==0xc0)
       {for(ic;ic<lm;ic++)
            pauseb0(ic)=0x04;      //stop
       }
  else
       {for(ic;ic<lm;ic++)
            pauseb0(ic)=0x05;       ///pause
       }
  quitok();
  return;     //get sch success,  back aa,55 ,33

}
//
void get_resume(void)     //F4
{uint ic,lm;
  for(ic=0;ic<4;ic++)
       { get1char();
          if (riflag!=1)
          {quiterror();
          return;
          }
         dst_buf[ic]=SBUF; // READ SBUF
       }
  ic=dst_buf[1];
  ic<<=8;
  ic+=dst_buf[0];
  ic&=0x03f;              //begin cell


  lm=dst_buf[3];
  lm<<=8;
  lm+=dst_buf[2];
  lm&=0x003f;
  lm+=ic;

  for(ic;ic<lm;ic++)
       resumeb0(ic)=0x05;       ///wake up

 quitok();
  return;     //get sch success,  back aa,55 ,33


}
void send_calidat(void)
{ uchar zn,zc,ic;
  _nop_();
  snd1char(0xaa);
  _nop_();
  snd1char(0x55);
  _nop_();
  for(ic=0;ic<8;ic++)          //(send_sum)
      {
       snd1char(cali_buf[ic]);    //snd1char(real_buf[ic]);
      }
     closechfg=1;

          quitok();
          return;     //get sch success,  back aa,55 ,33


}
//
void begin_test(void)
{ uchar zx,tempj[2];
 for(zx=0;zx<2;zx++)
       { get1char();
          if (riflag!=1)
          {quiterror();
          return;
          }
         tempj[zx]=SBUF; // READ SBUF
       }
 if(tempj[0]==tempj[1])
        {
         //get channell
         realchafg=tempj[0];  //get channell
         realtstfg=1;
          quitok();
          return;     //get sch success,  back aa,55 ,33
        }
 quiterror();
  return;     //get sch success,  back aa,55 ,33
}
//
void locate_start(void) //reentrant
{ uchar zx,tempj[2];
 for(zx=0;zx<2;zx++)
       { get1char();
          if (riflag!=1)
          {quiterror();
          return;
          }
         tempj[zx]=SBUF; // READ SBUF
       }
 if(tempj[0]==tempj[1])
        { startch=tempj[1];
          startchfg=0x1;
         //get channell

          quitok();
          return;     //get sch success,  back aa,55 ,33
    }
 quiterror();
  return;     //get sch success,  back aa,55 ,33
}
void get_2da(void)
{ uchar ic,im;
 for(ic=0;ic<132;ic++)
       { get1char();
          if (riflag!=1)
          {quiterror();
          return;
          }
         dst_buf[ic]=SBUF; // READ SBUF
       }

 for(ic=0;ic<4;ic++)
     {for(im=0;im<16;im++)
      {vi2da0(ic+2*im)=dst_buf[ic*32+im*2];
       vi2da0(ic+2*im+1)=dst_buf[ic*32+im*2+1];
      }
     }
 got_2da(0)=0x01;
 got_2da(1)=0x01;
 got_2da(2)=0x01;
 got_2da(3)=0x01;
 quitok();
  return;     //get sch success,  back aa,55 ,33
}
/////////////////////////////////////////////////////////
void set_time(void)     //F0
{ uchar ic,bb;
 for(ic=0;ic<8;ic++)     //校时8字节
       { get1char();
          if (riflag!=1)
          {quiterror();
          return;
          }
         dst_buf[ic]=SBUF; // READ SBUF
       }
 if(dst_buf[7]==0x5a)
     {for(ic=0;ic<8;ic++)
           timebk(ic+8)=dst_buf[ic];
     }
//bc
  ic=((timebk(8)/10)<<4)&0xf0;
  bb= (timebk(8)%10)&0x0f;
  timebk(0)=ic|bb ;   //s
  ic=((timebk(9)/10)<<4)&0xf0;
  bb= (timebk(9)%10)&0x0f;
  timebk(1)=ic|bb ;   //s
  ic=((timebk(10)/10)<<4)&0xf0;
  bb= (timebk(10)%10)&0x0f;
  timebk(2)=ic|bb ;   //s
  ic=((timebk(11)/10)<<4)&0xf0;
  bb= (timebk(11)%10)&0x0f;
  timebk(3)=ic|bb ;   //s
  ic=((timebk(12)/10)<<4)&0xf0;
  bb= (timebk(12)%10)&0x0f;
  timebk(4)=ic|bb ;   //s
  ic=((timebk(13)/10)<<4)&0xf0;
  bb= (timebk(13)%10)&0x0f;
  timebk(5)=ic|bb ;   //s
  //


 //
quitok();
  return;     //get sch success,  back aa,55 ,33


}
///
void receive_sch(void)     //F1
{uint ic,im;
uchar zz=0;
 //uint data i,j, k,l;
 unsigned long int idata count1,count2=0 ;
  uchar tempj[2]={0,0};
  //if(newschfg>3)       //
 //    {quiterror();
 //    return;
 //    }
  count1=0;
  get1char();
  if (riflag!=1)
     {quiterror();
     return;
     }
  dst_buf[0]=SBUF;
  get1char();
  if (riflag!=1)
     {quiterror();
     return;
     }
  dst_buf[1]=SBUF;
  im=dst_buf[0]+dst_buf[1]*256;  //get the total data num.
  temp1bytexi= im;  //length

  //newschfg=count1;    //
  /////
  for(ic=0;ic<im-2;ic++)
       { get1char();
          if (riflag!=1)
          {quiterror();
          return;
          }
         dst_buf[ic+2]=SBUF; // READ SBUF
        }
      //
  count2=0;
  temp1bytexi=0;
  temp1byteyi=0;
  for(ic=0;ic<(im-6);ic++) //count1-4
         {_nop_();
          count2=count2+dst_buf[ic+2]; //temp1bytex ;//count2+recibuf[i+2] ;
         }
  temp1bytezi=count2;

 temp1bytexi=dst_buf[ic+2];
 count1=temp1bytexi;

 temp1bytexi=dst_buf[ic+3];
 temp1bytexi<<=8;
 count1+=temp1bytexi;

 temp1bytexi=dst_buf[ic+4];
 temp1bytexi<<=16;
 count1+=temp1bytexi;

  temp1byteyi=count1;
  if (count1==count2)//(count1==count2)
         {zz=(dst_buf[2+2]&0x03);  //sch zone num.
          for(ic=0;ic<im-6;ic++)
              {
               schbuf(zz+ic)=dst_buf[ic+2];
              }
          hvnewsch(zz)=dst_buf[2]; //schbuf(zz+0);//0x1; sch type
          newschfg(zz)=0;
          quitok();
        //  relatitm=0;
        //  relatotal=0;
        //  pccomutm=0;       //for pc
          return;     //get sch success,  back aa,55 ,33
         }
   quiterror();      //fail,  back aa,55 ,88
   return;


}
 /*
for(leny=0;leny<len-8;leny++)
                                                       {//sch_buf[leny]=dst_buf[leny+8];
                                                        y=(dst_buf[8+4]&0x03);  //sch zone num.
                                                        schbuf(y+leny)=dst_buf[leny+10];
                                                        hvnewsch(y)=dst_buf[2+8]; //schbuf(zz+0);//0x1; sch type
                                                        newschfg(y)=0;     */
/////////send_realdat
void send_realdat(void)             //F6
{// uint data i;
uint ic=0;
  uchar data tempj[4]={0};
  unsigned long int data count1=0,count2=0;
  _nop_();
  snd1char(0xaa);
  _nop_();
  snd1char(0x55);
  ////
  count2=0;
  temp1bytexi=0;
  temp1byteyi=0;
  for(ic=0;ic<send_sum-4;ic++) //count1-4
         {_nop_();
          count2=count2+real_buf[ic]; //temp1bytex ;//count2+recibuf[i+2] ; real_buf
         }
  temp1byteyi=count2;

⌨️ 快捷键说明

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