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

📄 main.lst

📁 Cygnal 公司的TCP/IP 协议及webserver2.0 的源代码
💻 LST
字号:
C51 COMPILER V7.07   MAIN                                                                  11/25/2003 15:47:49 PAGE 1   


C51 COMPILER V7.07, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN MAIN.OBJ
COMPILER INVOKED BY: D:\KEIL707\C51\BIN\C51.EXE MAIN.C OPTIMIZE(9,SPEED) BROWSE DEBUG OBJECTEXTEND

stmt level    source

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

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

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

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

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

 304   3            }
 305   2         }
 306   1      }
 307          
 308          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    472    ----
   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 + -