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

📄 main.lst

📁 世纪民生公司的带网络功能的单片机CS6209开发http服务器的演示源代码。
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   MAIN                                                                  10/12/2006 15:31:38 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN .\Release\main.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c LARGE OPTIMIZE(9,SIZE) BROWSE ORDER MODDP2 INCDIR(e:\releasePackage\
                    -release\inc\;..\..\inc\) DEBUG OBJECTEXTEND PRINT(.\Release\main.lst) OBJECT(.\Release\main.obj)

line level    source

   1          /*
   2           * 
   3           * main.c
   4           * 
   5           * Part of the Myson Century CS620X     demo program.
   6           *
   7           * Authors: LY Lin, WM Wang, IJ Chen, WH Lee
   8           *
   9           * main.c contains main program.
  10           *
  11           * This program was developed using the Keil 8051 C uVision 2 system.
  12           * The Keil compiler MUST be used if working with Myson Century supplied
  13           * firmware.
  14           *
  15          */
  16          
  17          
  18          #include <stdio.h>
  19          #include <ctype.h>
  20          #include <stdlib.h>
  21          #include <string.h>
  22          
  23          #include "hpserver.h"
  24          #include "timer.h"
  25          #include "ether.h"
  26          #include "netutil.h"
  27          #include "net.h"
  28          #include "ip.h"
  29          #include "tcp.h"
  30          #include "udp.h"
  31          #include "config.h"
  32          #include "utility.h"
  33          #include "libif.h"
  34          #include "hwi2c.h"
  35          #include "rs232.h"
  36          #include "http.h"
  37          #include "620xenet.h"
  38          #include "rtc_api.h"
  39          #include "iap.h"
  40          char ipfromwhere;  /* 1=i2c, 2=flash, 3=config.c*/                                                                              
  41          
  42          void do_poll(GENFRAME *gfp);
  43          void do_receive(GENFRAME *gfp);
  44          void init_MAC(char net_from_flag);
  45          int wheregetip(char from_eeprom_flag);
  46          void netconfig (NODE *np, char net_from_flag);
  47          void CS620X_init(void);
  48          extern tcpdebug ;                                /*Set to enable TCP debug message display*/
  49          extern statedebug ;                              /*Set to enable TCP state display*/
  50          
  51          void main(void)
  52          {
  53   1          int n;
  54   1          unsigned char cTmp;
C51 COMPILER V7.50   MAIN                                                                  10/12/2006 15:31:38 PAGE 2   

  55   1          char k=0;
  56   1          char IP_from_eeprom_flag;
  57   1          GENFRAME *gfp;
  58   1          TSOCK *ts;
  59   1      
  60   1          /* Debug flags.*/
  61   1          tcpdebug = 0;       /*Set to enable TCP debug message display*/
  62   1          statedebug = 0;     /*Set to enable TCP state display*/
  63   1      
  64   1              /*
  65   1              disable RTC register write protect.
  66   1              */
  67   1              XBYTE[RTCMASK]=0x55;
  68   1              XBYTE[RTCMASK]=0xaa;
  69   1          /*
  70   1              Initialize the system: RS232 and Clock . This function 
  71   1              must be called before any other. 
  72   1          */
  73   1          CS620X_init();
  74   1      
  75   1          /*
  76   1              Initialize the RS232 driver with RX FIFO. If you don't want to use the Keil
  77   1              in-system debugger, don't call this function.
  78   1          */
  79   1           RS232_intr_init();
  80   1      
  81   1          /* System sign-on message. */
  82   1          printf("CS6209C0  Demo : HTTP demo \n");
  83   1      
  84   1          /* Initialize timer2 for TCP/IP timout functions. */
  85   1          init_timer2() ;
  86   1      
  87   1          /* Check for serial eeprom on evaluation board. */
  88   1          IP_from_eeprom_flag = detect_24256();
  89   1        
  90   1          if (!IP_from_eeprom_flag)
  91   1              printf("\nCannot find 24C256 EEPROM.\n");
  92   1      
  93   1          wheregetip(IP_from_eeprom_flag);
  94   1      
  95   1          /* 
  96   1              Initialize the MAC address and start the network interface.
  97   1              After calling this function, the network interface can receive 
  98   1              and transmit packets.
  99   1          */
 100   1          init_MAC (ipfromwhere);  
 101   1          /*Atfter this line , the net interface can receive and transmit packets.*/
 102   1          /* 
 103   1              Initialize the genframe structure. 
 104   1              Driver type is Ethernet.
 105   1          */
 106   1          genframe.g.dtype = DTYPE_ETHER;
 107   1      
 108   1          /* set a pointer to the genframe structure for later use. */
 109   1          gfp= &genframe;                     
 110   1      
 111   1          /* Initialize GENFRAME buffer. */
 112   1          gfp->buff=&nic_xmit_buf[0];
 113   1          gfp_buff_flag=0;
 114   1              
 115   1          /* Initialize the sockets.*/
 116   1          for (n = 0, ts = &tsocks[0]; n < NSOCKS; n++, ts++)
C51 COMPILER V7.50   MAIN                                                                  10/12/2006 15:31:38 PAGE 3   

 117   1          {
 118   2                 ts->index = n+1;
 119   2                 ts->txb.len = _CBUFFLEN_;
 120   2                 ts->txb.b_data =     &tsock_txb [n*_CBUFFLEN_];
 121   2      
 122   2                 ts->rxb.b_data_length = 0;
 123   2      #if     NO_SOCKET_RXB
                         ts->rxb.len = 0;
              #else
 126   2                 ts->rxb.len = _CBUFFLEN_;
 127   2                 ts->rxb.b_data =     &tsock_rxb [n*_CBUFFLEN_];
 128   2      #endif
 129   2                 ts->state=TCP_CLOSED;
 130   2          }
 131   1      
 132   1          /* Set the IP Address, Gateway Address, and Netmask. */             
 133   1          netconfig (&locnode,ipfromwhere);   
 134   1      
 135   1          /* Print network parameters on the rs232 interface. */
 136   1          show_menu (&locnode,0);                                  
 137   1      
 138   1          /* Initialize HTTP server and file system for it.*/ 
 139   1          http_init ();
 140   1          //init_rtc();
 141   1          /* Main     loop... */      
 142   1          while (1)                   
 143   1          {
 144   2              /* Check RS232 and set IP,Gateway,Net Mask if necessary */
 145   2               poll_set_ip();
 146   2               /* Waits for the incoming packets,also handles requests. */
 147   2               do_receive(gfp);                                       
 148   2      
 149   2               if (!RS232_rx_empty())
 150   2               {
 151   3                     cTmp = RS232_rx_getchar();
 152   3                     putchar(cTmp);
 153   3      
 154   3               }
 155   2               /* Poll        net     drivers .*/
 156   2               do_poll(gfp);
 157   2               if (!RS232_rx_empty())
 158   2               {
 159   3                     cTmp = RS232_rx_getchar();
 160   3                       putchar(cTmp);
 161   3      
 162   3               }                      
 163   2                       
 164   2          }
 165   1              
 166   1      }
 167          /************************************************************************
 168          /*      Function Name : init_MAC                                                                                        *
 169          /*                                                                                                                                              *
 170          /*      Arguments :                                                                                                             *
 171          /*                      char from_eeprom_flag:Set to read MAC address from EEPROM.      *
 172          /*                                                                                                                                              *
 173          /*      Return : None.                                                                                                          *
 174          /*                                                                                                                                              *
 175          /*                                                                                                                                              *
 176          /*  Comment :                                                                                                                   *
 177          /*                      This function sets the MAC address, then starts the network *
 178          /*                      interface. Attempts to read network parameters from serial      *
C51 COMPILER V7.50   MAIN                                                                  10/12/2006 15:31:38 PAGE 4   

 179          /*                      eeprom if the 'from_eeprom_flag' is set, otherwise defaults     *
 180          /*                      to config.c.                                                                                            *
 181          /*                                                                                                                                              *
 182          /************************************************************************/
 183          void init_MAC(char net_from_flag)
 184          {
 185   1            unsigned char mac[6];
 186   1            int i;
 187   1      
 188   1      
 189   1              if (net_from_flag==1)
 190   1              {
 191   2                      c256_pageread(I2C_MAC_START_ADDR,mac,MACLEN);//mac
 192   2                      for(i = 0; i<6; i++)
 193   2                              my_mac_addr[i] = mac[i];
 194   2      
 195   2              }
 196   1              else if(net_from_flag==2)
 197   1              {
 198   2                      IAP_pageread(FLASH_MAC_START_ADDR, mac, MACLEN);
 199   2                      for(i = 0; i<6; i++)
 200   2                              my_mac_addr[i] = mac[i];
 201   2      
 202   2              }
 203   1      
 204   1              init_ethernet();
 205   1                      
 206   1      }               
 207          
 208          int wheregetip(char from_eeprom_flag)
 209          {
 210   1              unsigned char mac[6];
 211   1              unsigned char   tempip[6];
 212   1              unsigned char temptftp[4];
 213   1      
 214   1              if (from_eeprom_flag)
 215   1              {
 216   2                      c256_pageread(I2C_MAC_START_ADDR,mac,MACLEN);//mac
 217   2                      c256_pageread(I2C_IP_START_ADDR,&tempip[0],4);
 218   2                      c256_pageread(I2C_TFTP_SERVER_ADDR, &temptftp[0], 4);
 219   2                      
 220   2                      if(((mac[0]&0x01) == 0) && (tempip[0]<248) && (temptftp[0]<248))
 221   2                      {
 222   3                              ipfromwhere = 1;   /*from I2C*/
 223   3                              printf("Read network configuration from I2C \n");
 224   3                              return 1;
 225   3                      }

⌨️ 快捷键说明

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