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

📄 main.lst

📁 tcpip.rar 是一个51控制8019的程序,我已用于商用.还很稳定,有兴趣的可以看一下,对TCP IP UDP ICMP ARP RARP HTTP均可以实现.
💻 LST
字号:
C51 COMPILER V7.06   MAIN                                                                  05/19/2004 15:53:17 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN MAIN.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE MAIN.C LARGE BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          //---------------------------------------------------------------------------
   2          // Net MAIN.C
   3          //
   4          // 8051 Web Server project
   5          // See Makefile for build notes 
   6          // Written for Keil C51 V5.1 compiler, notes:
   7          //   It uses big endian order, which is the same as the
   8          //   network byte order, unlike x86 systems.
   9          //   Use OPTIMIZE(2)or higher so that automatic variables get shared
  10          //   between functions, to stay within the 256 bytes idata space
  11          //---------------------------------------------------------------------------
  12          
  13          #include <string.h>
  14          #include <stdlib.h>
  15          #include <reg52.h>
  16          #include <stdio.h>
  17          #include "net.h"
  18          #include "eth.h"
  19          #include "serial.h"
  20          #include "timer.h"
  21          #include "analog.h"
  22          #include "arp.h"
  23          #include "tcp.h"
  24          #include "http.h"
  25          #include "ip.h"
  26          
  27          
  28          // Global variables
  29          UINT volatile event_word;
  30          char xdata text[20];  
  31          UCHAR idata debug;
  32          UCHAR idata rcve_buf_allocated;
  33          
  34          
  35          // This sets my hardware address to 00:01:02:03:04:05
  36          UCHAR code my_hwaddr[6] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03}; 
  37          
  38          // Hardware addr to send a broadcast
  39          UCHAR code broadcast_hwaddr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  40          
  41          // This sets my IP address to 192.168.0.10
  42          ULONG code  my_ipaddr = 0x0A0154FDL;
  43          
  44          // This sets my subnet mask to 255.255.255.0
  45          ULONG code my_subnet = 0xFFFFFF00L;
  46          
  47          // Set to 0 if no gateway is present on network
  48          ULONG code gateway_ipaddr = 0x0A015401L;
  49          
  50          //--------------------------------------------------------------------------
  51          // Initialize the memory management routines
  52          // Initialize variables declared in main
  53          //--------------------------------------------------------------------------
  54          
  55          unsigned int Count1msInc;
C51 COMPILER V7.06   MAIN                                                                  05/19/2004 15:53:17 PAGE 2   

  56          unsigned char Count1ms,Count10ms,Count1s;
  57          unsigned char TimeSecond,TimeMinute;
  58          
  59          void init_main(void)
  60          {
  61   1              // Start the memory pool for incoming and outgoing Ethernet
  62   1              // frames at 1000, with length = 1500 bytes. Memory below 500
  63   1              // is used for program variables
  64   1              init_mempool((void xdata *)1000, 1500);
  65   1              memset(text, 0, sizeof(text));
  66   1              event_word = 0;
  67   1              rcve_buf_allocated = FALSE;
  68   1              debug = 1;
  69   1      }
  70          
  71          
  72          
  73          void Timer_Init (void)
  74          {
  75   1              TMOD = 0X11;
  76   1              TF0 = 0;
  77   1              TH0 = 0XF8;             // set Timer0 to overflow in 1ms
  78   1              TL0 = 0X30;
  79   1              TR0 = 1;        // START Timer0
  80   1              ET0 = 1;
  81   1              TF1=0;
  82   1              TH1=0X4C;
  83   1              TL1=0;
  84   1              TR1=1;
  85   1              ET1=1;
  86   1      }
  87          
  88          void Timer0_ISR (void) interrupt 1  //1ms
  89          {
  90   1              TH0 = 0XF8;  
  91   1              TL0 = 0X30;
  92   1              if (Count1ms) Count1ms--;
  93   1              Count1msInc++;
  94   1              if (Count10ms) Count10ms--;
  95   1              else
  96   1              {
  97   2                      Count10ms=10;                           //10ms
  98   2                      if (Count1s) Count1s--;
  99   2                      else
 100   2                      {
 101   3                              Count1s=100;                    //1s
 102   3                              TimeSecond++;
 103   3                              if (TimeSecond>=60)
 104   3                              {
 105   4                                      TimeSecond=0;           //1min
 106   4                                      TimeMinute++;
 107   4                                      if      (TimeMinute==60)        TimeMinute=0;
 108   4                              }
 109   3                      }
 110   2              }
 111   1      }
 112          
 113          
 114          void Delay1ms(unsigned char T)
 115          {
 116   1              Count1ms=T;
 117   1              while (Count1ms);
C51 COMPILER V7.06   MAIN                                                                  05/19/2004 15:53:17 PAGE 3   

 118   1      }
 119          
 120          
 121          
 122          
 123          
 124          void LightONOFF(bit b)
 125          {
 126   1      if (b) {
 127   2              P1=254;
 128   2              }
 129   1              else
 130   1              {
 131   2              P1=255;
 132   2              }
 133   1      }
 134          
 135          
 136          void main (void)
 137          {
 138   1              UINT j, event_word_copy;
 139   1              UCHAR xdata * inbuf;
 140   1                              
 141   1      
 142   1      
 143   1              Timer_Init();
 144   1      
 145   1      
 146   1              init_main();
 147   1              init_tcp();
 148   1              init_http();
 149   1      
 150   1              EA=1;
 151   1              init_serial();
 152   1              if (debug) printf("Init OK!\n");
 153   1      
 154   1              init_arp();
 155   1              init_8019();
 156   1         
 157   1              
 158   1      
 159   1              j = 0;
 160   1      
 161   1                      
 162   1         // The code below is a priority based RTOS.  The event
 163   1         // handlers are in priority order - highest priority first.
 164   1              while (1)
 165   1         {
 166   2            // Query CS8900A to see if Ethernet frame has arrived
 167   2            // If so, set EVENT_ETH_ARRIVED bit in event_word
 168   2            query_8019();
 169   2            
 170   2            // Use a copy of event word to avoid interference
 171   2            // with interrupts
 172   2                      EA = 0;
 173   2                      event_word_copy = event_word;
 174   2                      EA = 1;
 175   2            
 176   2            // See if an Ethernet frame has arrived      
 177   2            if (event_word_copy & EVENT_ETH_ARRIVED)
 178   2            {
 179   3               EA = 0;
C51 COMPILER V7.06   MAIN                                                                  05/19/2004 15:53:17 PAGE 4   

 180   3               event_word &= (~EVENT_ETH_ARRIVED);
 181   3               EA = 1;
 182   3               
 183   3               // Allocate a buffer and read frame from CS8900A
 184   3               inbuf = rcve_frame();
 185   3               if (inbuf != NULL)
 186   3               {
 187   4                  // Process the received Ethernet frame 
 188   4                  eth_rcve(inbuf); 
 189   4               
 190   4                  // If the memory allocated for the rcve message has
 191   4                  // not already been freed then free it now
 192   4                  if (rcve_buf_allocated)
 193   4                  {
 194   5                     free(inbuf);
 195   5                     rcve_buf_allocated = FALSE;
 196   5                  }
 197   4               }
 198   3            }
 199   2            
 200   2            // See if TCP retransmit timer has expired                       
 201   2            else if (event_word_copy & EVENT_TCP_RETRANSMIT)
 202   2            {
 203   3               EA = 0;
 204   3               event_word &= (~EVENT_TCP_RETRANSMIT);
 205   3               EA = 1;
 206   3               tcp_retransmit();
 207   3                      }
 208   2      
 209   2            // See if TCP inactivity timer has expired
 210   2            else if (event_word_copy & EVENT_TCP_INACTIVITY)
 211   2            {
 212   3               EA = 0;
 213   3               event_word &= (~EVENT_TCP_INACTIVITY);
 214   3               EA = 1;
 215   3               tcp_inactivity();
 216   3                      }
 217   2      
 218   2            // See if ARP retransmit timer has expired
 219   2                      else if (event_word_copy & EVENT_ARP_RETRANSMIT)
 220   2            {
 221   3               EA = 0;
 222   3               event_word &= (~EVENT_ARP_RETRANSMIT);
 223   3               EA = 1;
 224   3               arp_retransmit();
 225   3                      }
 226   2      
 227   2            // See if it is time to age the ARP cache
 228   2            else if (event_word_copy & EVENT_AGE_ARP_CACHE)
 229   2            {
 230   3               EA = 0;
 231   3               event_word &= (~EVENT_AGE_ARP_CACHE);
 232   3                              EA = 1;
 233   3               age_arp_cache();
 234   3                      }
 235   2      
 236   2                      // See if it is time to read the analog inputs
 237   2                      else if (event_word_copy & EVENT_READ_ANALOG)
 238   2            {
 239   3               EA = 0;
 240   3               event_word &= (~EVENT_READ_ANALOG);
 241   3               EA = 1;
C51 COMPILER V7.06   MAIN                                                                  05/19/2004 15:53:17 PAGE 5   

 242   3                              // Read one of the 3 analog inputs each time
 243   3                              read_analog_inputs();
 244   3            }
 245   2      
 246   2                      // See if an RS232 message has arrived.  It is
 247   2            // not handled - RS232 is used for sending only
 248   2                      else if (event_word_copy & EVENT_RS232_ARRIVED)
 249   2            {
 250   3               EA = 0;
 251   3               event_word &= (~EVENT_RS232_ARRIVED);
 252   3               EA = 1;
 253   3            }
 254   2         }
 255   1      }
 256          
 257          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    465    ----
   CONSTANT SIZE    =     34    ----
   XDATA SIZE       =     29       6
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =      2    ----
   BIT SIZE         =   ----       1
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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