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

📄 main.lst

📁 用c8051f340基于51单片机上网
💻 LST
📖 第 1 页 / 共 3 页
字号:
 224   2            
 225   2            // Initialize timer to time out in one second
 226   2            reset_timeout(ONE_SECOND);
 227   2      
 228   2            // Reset receive buffer and enable interrupts
 229   2            RXCN = RXCLEAR;
 230   2                EIE1 |= 0x80;                         //ET3 = 1;
 231   2            EA  =  1;
 232   2            
 233   2            while(1){
 234   3               
 235   3               //--------------------------------------------------------------------
 236   3               // Task #1 
 237   3               // Exit application loop if device is removed from network
 238   3               //--------------------------------------------------------------------
 239   3               if(!(PHYCN & LINKSTA))        // Check the link status bit
 240   3               {                             // On detection of bad link:
 241   4                  YELLOW_LED = 0;            // Turn off the indicator
C51 COMPILER V8.08   MAIN                                                                  11/04/2008 18:45:33 PAGE 5   

 242   4                  break;                     // Exit application loop
 243   4               }
 244   3               
 245   3               //--------------------------------------------------------------------
 246   3               // Task #2
 247   3               // Check if a packet has been received
 248   3               //--------------------------------------------------------------------
 249   3               if(CPINFOH & RXVALID)         // Check if the current packet is valid
 250   3               {                             // On detection of a valid packet:
 251   4            
 252   4                  // Unload packet from the receive buffer and store in <RX_BUFF>   
 253   4                  num_bytes = CP220x_Receive(RX_BUFF, sizeof(RX_BUFF));
 254   4                  
 255   4                  //-----------------------------------------------------------------
 256   4                  // Application-Specific Code:
 257   4                  // If UART is enabled, print packet statistics to the terminal.
 258   4                  //-----------------------------------------------------------------
 259   4                  #if(UART_ENABLED)
 260   4                  
 261   4                     // Print the number of bytes received.      
 262   4                     printf("Received Packet (%i bytes)\n", num_bytes);
 263   4                 
 264   4                     // Print each byte to the UART terminal
 265   4                     for(i = 0; i < num_bytes; i++)
 266   4                     {
 267   5                          // Create a new row every 16 bytes
 268   5                        if((i & 0x000F) == 0x0000)
 269   5                        { 
 270   6                           // Print the row address in the left column
 271   6                           printf("\n%04X   ", i);
 272   6                        }
 273   5                     
 274   5                        // Print the byte
 275   5                        printf("%02bX ", RX_BUFF[i]);
 276   5                     }
 277   4                  
 278   4                     // Print two new-line characters for clarity (whitespace).
 279   4                     printf("\n\n");
 280   4                 
 281   4                  #endif
 282   4            
 283   4               } 
 284   3      
 285   3               //--------------------------------------------------------------------
 286   3               // Task #3
 287   3               // Check if timer has expired. Send one packet every second.
 288   3               //--------------------------------------------------------------------
 289   3               if(timeout_expired()){
 290   4                  
 291   4                  // Reset timer to time out again after another second.
 292   4                  reset_timeout(ONE_SECOND);
 293   4                  
 294   4                  // Send one packet.
 295   4                  CP220x_Send(&DESTMAC, TX_BUFF, sizeof(TX_BUFF), IP_PACKET);
 296   4               }      
 297   3      //////////copy web340    // 下面代码为设置何种事件中断发生,以做出相应的处理
 298   3              if(CPINFOH & RXVALID)  
 299   3                event_word |= EVENT_ETH_ARRIVED;
 300   3                event_word_copy = event_word;
 301   3                        EA = 1;
 302   3             if (event_word_copy & EVENT_ETH_ARRIVED)
 303   3                {
C51 COMPILER V8.08   MAIN                                                                  11/04/2008 18:45:33 PAGE 6   

 304   4                    EA = 0;
 305   4                    event_word &= (~EVENT_ETH_ARRIVED);
 306   4                    EA = 1;
 307   4                    inbuf = rcve_frame();
 308   4                    if (inbuf != NULL)
 309   4                      {
 310   5                        eth_rcve(inbuf); 
 311   5                           if (rcve_buf_allocated)
 312   5                        {
 313   6                                         rcve_buf_allocated = FALSE;
 314   6                        }
 315   5                       }
 316   4                 }
 317   3            
 318   3                                     
 319   3            else if (event_word_copy & EVENT_TCP_RETRANSMIT) //判断TCP传输是否超时
 320   3            {
 321   4               event_word &= (~EVENT_TCP_RETRANSMIT);
 322   4               EA = 1;
 323   4               tcp_retransmit();
 324   4                      }
 325   3      
 326   3             else if (event_word_copy & EVENT_TCP_INACTIVITY)//判断TCP休止时间
 327   3            {
 328   4               event_word &= (~EVENT_TCP_INACTIVITY);
 329   4               EA = 1;
 330   4               tcp_inactivity();
 331   4                      }
 332   3      
 333   3           
 334   3                      else if (event_word_copy & EVENT_ARP_RETRANSMIT) //判断ARP传输是否超时
 335   3            {
 336   4               event_word &= (~EVENT_ARP_RETRANSMIT);
 337   4               EA = 1;
 338   4               arp_retransmit();
 339   4                      }
 340   3      
 341   3           else if (event_word_copy & EVENT_AGE_ARP_CACHE)
 342   3            {
 343   4               event_word &= (~EVENT_AGE_ARP_CACHE);
 344   4                              EA = 1;
 345   4               age_arp_cache();
 346   4                      }
 347   3      
 348   3                      else if (event_word_copy & EVENT_READ_ANALOG)   //读AD输入的时间
 349   3            {
 350   4               event_word &= (~EVENT_READ_ANALOG);
 351   4               EA = 1;
 352   4                      
 353   4                      ///     read_analog_inputs();
 354   4            }
 355   3      
 356   3              
 357   3                      else if (event_word_copy & EVENT_RS232_ARRIVED)
 358   3            {
 359   4               event_word &= (~EVENT_RS232_ARRIVED);
 360   4               EA = 1;
 361   4            }
 362   3      //////////copy web340      
 363   3            //-----------------------------
 364   3            // End Main Application Loop
 365   3            //----------------------------- 
C51 COMPILER V8.08   MAIN                                                                  11/04/2008 18:45:33 PAGE 7   

 366   3            }          
 367   2      
 368   2         
 369   2      
 370   2         // Main do-while initialization loop -- code execution will now restart 
 371   2         } while(1);
 372   1      }
 373          
 374          //-----------------------------------------------------------------------------
 375          // Ethernet_ISR
 376          //-----------------------------------------------------------------------------
 377          //
 378          // This Interrupt Service Routine checks the number of packets in the receive
 379          // buffer after each packet is received. If the buffer has 7 or more packets,
 380          // then packet reception is disabled. Packet reception is re-enabled in the 
 381          // CP220x_Receive() routine after all packets have been unloaded.
 382          //
 383          // Allowed Latency: This interrupt service routine should be serviced within
 384          //                  51.2 us of the interrupt flag. This is the amount of time
 385          //                  it takes to receive a minimum-sized 64-byte packet. To 
 386          //                  allow for greater latency (51.2us/packet), the maximum 
 387          //                  number of packets allowed in the receive buffer can be 
 388          //                  decreased.
 389          //-----------------------------------------------------------------------------
 390          void Ethernet_ISR(void)
 391          {
 392   1         unsigned char interrupt_read;
 393   1         unsigned char valid_bits;
 394   1         unsigned char num_packets;
 395   1      
 396   1         // Clear interrupt flags.
 397   1         interrupt_read = INT1;
 398   1         interrupt_read = INT0;
 399   1         
 400   1         // Check for packet received interrupt
 401   1         if( interrupt_read & RXINT)
 402   1         {   
 403   2            // Count the number of packets in the receive buffer         
 404   2            // This is equal to the number of bits set to 1 in TLBVALID
 405   2            valid_bits = TLBVALID;     
 406   2                                 
 407   2            // Loop accumulates the number of bits set in Valid_Bits and 
 408   2            // stores this value in i. Uses the Brian Kernighan method 
 409   2            // for counting bits
 410   2            for(num_packets = 0; valid_bits; num_packets++)      
 411   2            {                                 
 412   3               valid_bits &= valid_bits - 1; 
 413   3            }
 414   2         
 415   2            // If the receive buffer has 7 packets, then disable reception.
 416   2            if( num_packets >= 7) 
 417   2            {
 418   3               RXCN = RXINH;           // Inhibit New Packet Reception
 419   3            }
 420   2         } 
 421   1         
 422   1         // Check for the FIFO Full Interrupt
 423   1         else if (interrupt_read & RXFINT)
 424   1         {
 425   2            // This interrupt could mean a few large packets were received,
 426   2            // or a large number of small packets were received.      
 427   2         } 
C51 COMPILER V8.08   MAIN                                                                  11/04/2008 18:45:33 PAGE 8   

 428   1         
 429   1      }
 430          
 431          
 432          /**************************************************************************/
 433          // 以太网帧接收函数
 434          /**************************************************************************/
 435          void eth_rcve(UCHAR xdata * inbuf)
 436          {
 437   1         ETH_HEADER xdata * eth;
 438   1         eth = (ETH_HEADER xdata *)inbuf;
 439   1         if (eth->frame_type < 1520)     // 帧长度不能超过IEEE 802标准归定
 440   1            {
 441   2                  return;      
 442   2            }
 443   1           
 444   1         switch (eth->frame_type)           //根据接收到的数据包类型,选择不同的处理方式
 445   1            {
 446   2                 case ARP_PACKET:
 447   2                      arp_rcve(inbuf);
 448   2                      break;
 449   2                            
 450   2                 case IP_PACKET:
 451   2                      ip_rcve(inbuf);
 452   2                  break;
 453   2                 default:break;

⌨️ 快捷键说明

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