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

📄 main.lst

📁 C8051单片机的TCPIP源程序 好用.
💻 LST
字号:
C51 COMPILER V8.01   MAIN                                                                  11/23/2005 11:07:36 PAGE 1   


C51 COMPILER V8.01, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN Main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Main.c BROWSE DEBUG OBJECTEXTEND

line 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 "C8051f.h"
  16          #include "net.h"
  17          #include "eth.h"
  18          #include "serial.h"
  19          #include "timer.h"
  20          #include "analog.h"
  21          #include "arp.h"
  22          #include "tcp.h"
  23          #include "http.h"
  24          #include "ip.h"
  25          
  26          
  27          // Global variables
  28          UINT volatile event_word;
  29          char xdata text[20];  
  30          UCHAR idata debug;
  31          UCHAR idata rcve_buf_allocated;
  32          
  33          
  34          // This sets my hardware address to 00:01:02:03:04:05
  35          UCHAR code my_hwaddr[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05}; 
  36          
  37          // Hardware addr to send a broadcast
  38          UCHAR code broadcast_hwaddr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  39          
  40          // This sets my IP address to 192.168.0.10
  41          ULONG code  my_ipaddr = 0xC0A8000AL;
  42          
  43          // This sets my subnet mask to 255.255.255.0
  44          ULONG code my_subnet = 0xFFFFFF00L;
  45          
  46          // Set to 0 if no gateway is present on network
  47          ULONG code gateway_ipaddr = 0;
  48          
  49          //--------------------------------------------------------------------------
  50          // Initialize the memory management routines
  51          // Initialize variables declared in main
  52          //--------------------------------------------------------------------------
  53          
  54          unsigned int Count1msInc;
  55          unsigned char Count1ms,Count10ms,Count1s;
C51 COMPILER V8.01   MAIN                                                                  11/23/2005 11:07:36 PAGE 2   

  56          unsigned char TimeSecond,TimeMinute;
  57          
  58          void init_main(void)
  59          {
  60   1              // Start the memory pool for incoming and outgoing Ethernet
  61   1              // frames at 1000, with length = 1500 bytes. Memory below 500
  62   1              // is used for program variables
  63   1              init_mempool((void xdata *)1000, 1500);
  64   1              memset(text, 0, sizeof(text));
  65   1              event_word = 0;
  66   1              rcve_buf_allocated = FALSE;
  67   1              debug = FALSE;
  68   1      }
  69          
  70          void PORT_Init (void)
  71          {
  72   1         XBR0    = 0x07;                     // Enable SMBus, SPI0, and UART0
  73   1         XBR1    = 0x00;
  74   1         XBR2    = 0x44;                     // Enable crossbar and weak pull-ups
  75   1         EMI0TC  = 0x21;
  76   1         P74OUT  = 0xFF;
  77   1         P0MDOUT = 0x15;
  78   1      }
  79          
  80          void SPI0_Init (void)
  81          {
  82   1         SPI0CFG = 0x07;                     // data sampled on 1st SCK rising edge
  83   1                                             // 8-bit data words
  84   1         SPI0CFG|=0xC0;       //CKPOL =1;
  85   1      
  86   1         SPI0CN = 0x03;                      // Master mode; SPI enabled; flags
  87   1                                             // cleared
  88   1         SPI0CKR = SYSCLK/2/8000000-1;       // SPI clock <= 8MHz (limited by 
  89   1                                             // EEPROM spec.)
  90   1      }
  91          
  92          void Timer0_Init (void)
  93          {
  94   1              CKCON|=0x8;
  95   1              TMOD|=0x1;      //16Bit
  96   1              Count10ms=10;
  97   1              Count1s=0;
  98   1              TR0 = 0;                                // STOP Timer0
  99   1              TH0 = (-SYSCLK/1000) >> 8;              // set Timer0 to overflow in 1ms
 100   1              TL0 = -SYSCLK/1000;
 101   1              TR0 = 1;        // START Timer0
 102   1              IE|= 0x2; 
 103   1      }
 104          void SYSCLK_Init (void)
 105          {
 106   1         int i;                              // delay counter
 107   1         OSCXCN = 0x67;                      // start external oscillator with
 108   1                                             // 18.432MHz crystal
 109   1         for (i=0; i < 256; i++) ;           // Wait for osc. to start up
 110   1         while (!(OSCXCN & 0x80)) ;          // Wait for crystal osc. to settle
 111   1         OSCICN = 0x88;                      // select external oscillator as SYSCLK
 112   1                                             // source and enable missing clock
 113   1                                             // detector
 114   1      //      OSCICN = 0x07;   //interal 16MHZ
 115   1      }
 116          void Timer0_ISR (void) interrupt 1  //1ms
 117          {
C51 COMPILER V8.01   MAIN                                                                  11/23/2005 11:07:36 PAGE 3   

 118   1              TH0 = (-SYSCLK/1000) >> 8;  
 119   1              TL0 = -SYSCLK/1000;
 120   1              if (Count1ms) Count1ms--;
 121   1              Count1msInc++;
 122   1              if (Count10ms) Count10ms--;
 123   1              else
 124   1              {
 125   2                      Count10ms=10;                           //10ms
 126   2                      if (Count1s) Count1s--;
 127   2                      else
 128   2                      {
 129   3                              Count1s=100;                    //1s
 130   3                              TimeSecond++;
 131   3                              if (TimeSecond>=60)
 132   3                              {
 133   4                                      TimeSecond=0;           //1min
 134   4                                      TimeMinute++;
 135   4                                      if      (TimeMinute==60)        TimeMinute=0;
 136   4                              }
 137   3                      }
 138   2              }
 139   1      }
 140          
 141          
 142          void Delay1ms(unsigned char T)
 143          {
 144   1              Count1ms=T;
 145   1              while (Count1ms);
 146   1      }
 147          
 148          /*通过SPI发送一字节*/
 149          #define CHIP595_SELECT          P5 &= ~(0x10);                  // P54 
 150          #define CHIP_NOSELECT           P5 |= 0xf8;                     // P53-57 
 151          
 152          void SendSPIByte(unsigned char ch)
 153          {
 154   1                      SPIF = 0;
 155   1                      SPI0DAT = ch;
 156   1                      while (SPIF == 0);       // wait for data transfer to be completed                                      
 157   1      } 
 158          
 159          void LightONOFF(bit b)
 160          {
 161   1              CHIP_NOSELECT;  
 162   1              CHIP595_SELECT;
 163   1              SendSPIByte(0x0);
 164   1              if (b)
 165   1              {
 166   2                      SendSPIByte(0x01);
 167   2              }
 168   1              else
 169   1              {
 170   2                      SendSPIByte(0x00);
 171   2              }
 172   1              CHIP_NOSELECT;  
 173   1      }
 174          
 175          
 176          void main (void)
 177          {
 178   1              UINT j, event_word_copy;
 179   1              UCHAR xdata * inbuf;
C51 COMPILER V8.01   MAIN                                                                  11/23/2005 11:07:36 PAGE 4   

 180   1                              
 181   1              WDTCN = 0xDE;              // Disable watchdog timer
 182   1              WDTCN = 0xAD;
 183   1      
 184   1              EMI0CF =0x24;                                           // share low 4K XRAM
 185   1              SYSCLK_Init ();                     // initialize oscillator
 186   1              Timer0_Init();
 187   1              PORT_Init ();                       // initialize crossbar and GPIO
 188   1              SPI0_Init ();                       // initialize SPI0
 189   1      
 190   1              init_main();
 191   1              init_tcp();
 192   1              init_http();
 193   1      
 194   1              EA=1;
 195   1              init_serial();
 196   1              SendCommString("Init OK\r\n");
 197   1      
 198   1              init_adc();
 199   1              init_timer2();
 200   1              init_arp();
 201   1              init_8019();
 202   1         
 203   1              
 204   1      
 205   1              j = 0;
 206   1              ET2 = 1;                            // Enable timer 2 interrupt
 207   1                      
 208   1         // The code below is a priority based RTOS.  The event
 209   1         // handlers are in priority order - highest priority first.
 210   1              while (1)
 211   1         {
 212   2            // Query CS8900A to see if Ethernet frame has arrived
 213   2            // If so, set EVENT_ETH_ARRIVED bit in event_word
 214   2            query_8019();
 215   2            
 216   2            // Use a copy of event word to avoid interference
 217   2            // with interrupts
 218   2                      EA = 0;
 219   2                      event_word_copy = event_word;
 220   2                      EA = 1;
 221   2            
 222   2            // See if an Ethernet frame has arrived      
 223   2            if (event_word_copy & EVENT_ETH_ARRIVED)
 224   2            {
 225   3               EA = 0;
 226   3               event_word &= (~EVENT_ETH_ARRIVED);
 227   3               EA = 1;
 228   3               
 229   3               // Allocate a buffer and read frame from CS8900A
 230   3               inbuf = rcve_frame();
 231   3               if (inbuf != NULL)
 232   3               {
 233   4                  // Process the received Ethernet frame 
 234   4                  eth_rcve(inbuf); 
 235   4               
 236   4                  // If the memory allocated for the rcve message has
 237   4                  // not already been freed then free it now
 238   4                  if (rcve_buf_allocated)
 239   4                  {
 240   5                     free(inbuf);
 241   5                     rcve_buf_allocated = FALSE;
C51 COMPILER V8.01   MAIN                                                                  11/23/2005 11:07:36 PAGE 5   

 242   5                  }
 243   4               }
 244   3            }
 245   2            
 246   2            // See if TCP retransmit timer has expired                       
 247   2            else if (event_word_copy & EVENT_TCP_RETRANSMIT)
 248   2            {
 249   3               EA = 0;
 250   3               event_word &= (~EVENT_TCP_RETRANSMIT);
 251   3               EA = 1;
 252   3               tcp_retransmit();
 253   3                      }
 254   2      
 255   2            // See if TCP inactivity timer has expired
 256   2            else if (event_word_copy & EVENT_TCP_INACTIVITY)
 257   2            {
 258   3               EA = 0;
 259   3               event_word &= (~EVENT_TCP_INACTIVITY);
 260   3               EA = 1;
 261   3               tcp_inactivity();
 262   3                      }
 263   2      
 264   2            // See if ARP retransmit timer has expired
 265   2                      else if (event_word_copy & EVENT_ARP_RETRANSMIT)
 266   2            {
 267   3               EA = 0;
 268   3               event_word &= (~EVENT_ARP_RETRANSMIT);
 269   3               EA = 1;
 270   3               arp_retransmit();
 271   3                      }
 272   2      
 273   2            // See if it is time to age the ARP cache
 274   2            else if (event_word_copy & EVENT_AGE_ARP_CACHE)
 275   2            {
 276   3               EA = 0;
 277   3               event_word &= (~EVENT_AGE_ARP_CACHE);
 278   3                              EA = 1;
 279   3               age_arp_cache();
 280   3                      }
 281   2      
 282   2                      // See if it is time to read the analog inputs
 283   2                      else if (event_word_copy & EVENT_READ_ANALOG)
 284   2            {
 285   3               EA = 0;
 286   3               event_word &= (~EVENT_READ_ANALOG);
 287   3               EA = 1;
 288   3                              // Read one of the 3 analog inputs each time
 289   3                              read_analog_inputs();
 290   3            }
 291   2      
 292   2                      // See if an RS232 message has arrived.  It is
 293   2            // not handled - RS232 is used for sending only
 294   2                      else if (event_word_copy & EVENT_RS232_ARRIVED)
 295   2            {
 296   3               EA = 0;
 297   3               event_word &= (~EVENT_RS232_ARRIVED);
 298   3               EA = 1;
 299   3            }
 300   2         }
 301   1      }
 302          
 303          
C51 COMPILER V8.01   MAIN                                                                  11/23/2005 11:07:36 PAGE 6   



MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    463    ----
   CONSTANT SIZE    =     34    ----
   XDATA SIZE       =     20    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      9       6
   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 + -