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

📄 main.lst

📁 51 单片机上网
💻 LST
📖 第 1 页 / 共 2 页
字号:
 252          /*************************************************************************/
 253          /*
 254          void timer0_interrupt(void)  interrupt 1
 255          {
 256                  TL0=TL0+LOW(timer_10ms_value);                          //reload timer0
 257                  TH0=TH0+HIGH(timer_10ms_value);
 258                  if (uart_receiving)
 259                  {
 260                          if (uart_char_space<6)
 261                                  uart_char_space++;
 262                          else
 263                          {
 264                                  uart_receiving=FALSE;
 265                                  uart_receive_enable=FALSE;
 266                                  uart_received_finished=TRUE;
 267                                  uart_frame_space=0;
 268                          }
 269                          uart_frame_space=0;
 270                  }
 271                  else
 272                  {
 273                          if (!uart_receive_enable)
 274                          {
 275                                  uart_frame_space++;
 276                                  if (uart_frame_space>8)
 277                                  {
 278                                          uart_frame_space=0;
 279                                          uart_receive_enable=TRUE;
 280                                  }
 281                           }
 282                  }
 283                  if (uart_trans_willing)
 284                  {
 285                                  uart_trans_willing=FALSE;
 286                                  TI=1;
 287                  }
 288                  
 289              if (being_echo)
 290              {
 291                       net_overtime_count++;
 292                       if (net_overtime_count>18000)
 293                       {
 294                          being_echo=0;
 295                          if (first_arp)
 296                                  first_arp=0;
 297                          else    
 298                                  remote_echo=1;
 299                          net_overtime_count=0;
 300                       }
 301              }           
 302                  runtime++;
 303                  dog++;
C51 COMPILER V7.07   MAIN                                                                  06/30/2006 16:21:50 PAGE 6   

 304          }
 305          */
 306          
 307          /*************************************************************************/
 308          //    串口中断程序,该程序在认为串口的接收是终端在响应串口的发送
 309          //    在串口未发送完成之前,不处理完罗接收的数据
 310          /*************************************************************************/
 311          /*
 312          void uart_interrupt(void)  interrupt 4 
 313          {
 314                  if (RI)
 315                  {
 316                          RI=0;
 317                          if ((!uart_received_finished)&& uart_receive_enable)
 318                          {
 319                                  if (!uart_receiving)
 320                                  {
 321                                          uart_receiving=1;
 322                                          uart_receive_count=0;
 323                                          uart_receive_buf[uart_receive_count++]=SBUF;
 324                                  }
 325                                  else
 326                                  {
 327                                          uart_char_space=0;
 328                                          uart_receive_buf[uart_receive_count++]=SBUF;
 329                                  }
 330                          }
 331                  }
 332                  if (TI)
 333                  {
 334                          TI=0;
 335                          if (uart_trans_count<uart_trans_length)
 336                          {
 337                                          ACC=uart_trans_buf[uart_trans_count++];
 338                                          TB8=P;
 339                                          SBUF=ACC;
 340                          }
 341                          else
 342                          {
 343                                          uart_trans_finished=1;
 344                                          uart_trans_count=0;
 345                                          uart_trans_length=0;
 346                          }
 347                                          
 348                  }
 349          }
 350          */
 351          
 352          //*******************************************************************************
 353          /* Receive a UDP datagram: return non-0 if client state-change */
 354          //*******************************************************************************
 355          int udp_receive(ETHERFRAME *efp, int len)
 356          {
 357   1          UDPKT *udp;
 358   1          int ret=0;
 359   1          NODE loc, rem;
 360   1      
 361   1          udp = (UDPKT *)efp->edata;
 362   1          getudp_srce(efp, &rem);                         /* Get srce & dest nodes */
 363   1          getudp_locdest(efp, &loc);
 364   1          if (loc.port == locnode.port)                   /* Client response */
 365   1          {
C51 COMPILER V7.07   MAIN                                                                  06/30/2006 16:21:50 PAGE 7   

 366   2              //      UDP 将数据拷贝至串口接收缓冲区,置接收完成标志(在合并方式)
 367   2              //              UDP 将数据拷贝至串口发送缓冲区,置发送标志(在模块方式)
 368   2      //        EA=0;
 369   2              memcpy(uart_trans_buf+uart_trans_length,udp->udpdata,len);
 370   2              uart_trans_length=uart_trans_length+len;
 371   2              uart_trans_finished=0;
 372   2              if (uart_trans_count==0)
 373   2                                      uart_trans_willing=1;
 374   2      //              EA=1;        
 375   2              ret = CLIENT_DONE;                          /* ..and exit */
 376   2          }
 377   1          else if (loc.port == ECHOPORT)                  /* Echo req: resend data */
 378   1              udp_transmit(efp, &loc, &rem, udp->udpdata, len);
 379   1          return(ret);
 380   1      }
 381          
 382          /*****************************************************************/
 383          //本机的网络处理子程序
 384          /*****************************************************************/
 385          int do_net_process(ETHERFRAME *efp,int rxlen)
 386          {
 387   1              ARPKT *arp;
 388   1              IPKT  *ip;
 389   1              ICMPKT *icmp;
 390   1              NODE node;
 391   1              int txlen;
 392   1              int len;
 393   1              int ret=0;
 394   1      
 395   1              ip=(IPKT *)efp->edata;
 396   1              if (is_arp(efp,rxlen))
 397   1              {
 398   2                  arp = (ARPKT *)efp->edata;
 399   2                    
 400   2                  if (arp->op==ARPREQ && arp->dip==locnode.ip)
 401   2                  {                                       /* ARP request? */
 402   3                      node.ip = arp->sip;                 /* Make ARP response */
 403   3                      memcpy(node.mac, arp->smac, MACLEN);
 404   3                      txlen = make_arp(efp, &locnode, &node, ARPRESP);
 405   3                      put_ethernet(efp, txlen);              /* Send packet */
 406   3                  }
 407   2                  if (arp->op==ARPRESP && arp->dip==locnode.ip)
 408   2                  {                                       /* ARP response? */
 409   3                      memcpy(remnode.mac,arp->smac, MACLEN);
 410   3                      being_echo=0;
 411   3                      if (first_arp)
 412   3                          first_arp=0;
 413   3                      else 
 414   3                          remote_echo=1;
 415   3                      ret = ARP_RX;
 416   3                  }
 417   2              }
 418   1          else if ((rxlen=is_ip(efp, rxlen))!=0)    /* IP datagram? */
 419   1                       if (ip->i.dip==locnode.ip || ip->i.dip==BCASTIP)
 420   1                                              
 421   1                {
 422   2                  getip_srce(efp, &node);
 423   2                  if ((len=is_icmp(ip, rxlen))!=0)        /* ICMP? */
 424   2                  {
 425   3                      icmp = (ICMPKT *)ip;
 426   3                      if (icmp->c.type == ICREQ)          /* Echo request? */
 427   3                      {
C51 COMPILER V7.07   MAIN                                                                  06/30/2006 16:21:50 PAGE 8   

 428   4                          len = (WORD)max(len, 0);       /* Make response */
 429   4                          txlen = make_icmp(efp, &locnode, &node, ICREP,
 430   4                                            icmp->c.codetype, (WORD)len);
 431   4                          put_ethernet(efp, txlen);          /* Send packet */
 432   4                      }
 433   3      //                else if (icmp->c.type == ICUNREACH)
 434   3      //                    printf("\r\nICMP: destination unreachable\r\n");
 435   3                  }
 436   2                  else if ((len=is_udp(ip, rxlen))!=0)    /* UDP? */
 437   2                  {
 438   3                      ret = udp_receive(efp, max(len, 0));
 439   3                  }
 440   2              }
 441   1              return (ret);
 442   1      }
 443          
 444          //**********************************
 445          void flush_gate_mac()
 446          {                       
 447   1              int ret;
 448   1      
 449   1              remote_echo=0;
 450   1              remnode.mac[0]=0xff;
 451   1              remnode.mac[1]=0xff;
 452   1              remnode.mac[2]=0xff;
 453   1              remnode.mac[3]=0xff;
 454   1              remnode.mac[4]=0xff;
 455   1              remnode.mac[5]=0xff;
 456   1              ret=make_arp(&etherframe,&locnode, &remnode, ARPREQ);           //请求网关或控制主机的物理地址
 457   1              put_ethernet(&etherframe,ret);
 458   1              being_echo=1;
 459   1      }
 460          
 461          //************************************************
 462          void do_uart_process(void)
 463          {
 464   1              if (being_echo==0)                      // 1 arp wait response
 465   1              {
 466   2              if (remote_echo==0)
 467   2              {
 468   3                              if (!memcmp(remnode.mac, bcast, MACLEN))
 469   3                                      flush_gate_mac();
 470   3                              else
 471   3                                      send_ip();
 472   3                      }               
 473   2                      else
 474   2                      {
 475   3                               remote_echo=0;
 476   3                               send_ip();
 477   3                      }        
 478   2               }
 479   1      }
 480          
 481          //************************************************
 482          void send_ip(void)
 483          {
 484   1              int ret;
 485   1      
 486   1          memcpy((BYTE *)&etherframe+sizeof(ETHERHDR)+sizeof(IPHDR)+sizeof(UDPHDR),uart_receive_buf,uart_receive
             -_count);
 487   1              remnode.port=locnode.port;
 488   1              ret=make_udp(&etherframe, &locnode,&remnode,(WORD)(uart_receive_count));
C51 COMPILER V7.07   MAIN                                                                  06/30/2006 16:21:50 PAGE 9   

 489   1              uart_received_finished=0;  
 490   1              uart_receive_count=0;
 491   1              put_ethernet(&etherframe,ret);
 492   1      }
 493          
 494          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1416    ----
   CONSTANT SIZE    =    156    ----
   XDATA SIZE       =   3623      90
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      8    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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