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

📄 main.lst

📁 RS232异步串行接口转以太网接口C语言程序源码
💻 LST
字号:
C51 COMPILER V7.50   MAIN                                                                  08/13/2006 23:44:28 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c DEBUG OBJECTEXTEND

line level    source

   1          // 本程序的晶体为 22.1184mHz
   2          // 本程序的缺省IP    192.168.0.7
   3          // 本程序的缺省mask  255.255.255.0
   4          // 本程序的缺省mac       0x1234567890ab
   5          // 本程序的缺省gate  0.0.0.0(无网关)
   6          // 本程序的缺省端口号port  9000
   7          // 本程序的缺省remote_ip  192.168.0.1
   8          
   9          //#include <reg52.h>
  10          #include <absacc.h>
  11          #include <stdio.h>
  12          #include <stdlib.h>
  13          #include <string.h>
  14          #include <intrins.h>
  15          //#include "24c02.h"
  16          //#include "ethernet.h"
  17          //#include "ip.h"
  18          //#include "udp.h"
  19          
  20          
  21          //波特率 是在smod=1 的情况下计算的
  22          #define FALSE       0
  23          #define TRUE        1
  24          #define false       0
  25          #define true        1
  26          
  27          #define BPS600      0x40
  28          #define BPS1200     0xA0        
  29          #define BPS2400     0xD0        
  30          #define BPS4800     0xE8
  31          #define BPS9600     0xF4
  32          #define BPS14400        0xF8
  33          #define BPS19200        0xFA
  34          #define BPS28800        0xFC
  35          #define BPS38400        0xFD
  36          
  37          
  38          
  39          #define timer_5ms_value  0xDC00
  40          #define timer_10ms_value 0xB800
  41          #define timer_20ms_value 0x7000
  42          
  43          #define rom_ip                  0x00
  44          #define rom_mask                0x04
  45          #define rom_gate                0x08
  46          #define rom_remote_ip   0x0c
  47          #define rom_mac                 0x10
  48          #define rom_port        0x16
  49          
  50          #define ARP_TX      1               /* Client state: sending ARP */
  51          #define ARP_RX      2               /*               received ARP */
  52          #define CLIENT_DONE 3               /*               completed */
  53          
  54          #define HIGH(x) (x &0xff00)>>8
  55          #define LOW(x) (x &0xff)
C51 COMPILER V7.50   MAIN                                                                  08/13/2006 23:44:28 PAGE 2   

  56          sbit watch_dog=0xb5;
  57          sbit run_led=0x95;
  58          
  59          //BYTE bcast[MACLEN]={BCASTADDR};       //  该变量为源广播地址mac
  60          //BYTE code default_mac[MACLEN]={0x12,0x34,0x56,0x78,0x90,0xab};  
  61          bit  uart_receive_enable;               // 串口接收允许标志
  62          bit  uart_receiving;                            // 串口正在接收标志
  63          bit  uart_received_finished;            // 串口接收完成标志
  64          bit  uart_trans_willing;                                // 串口将要发送标志
  65          bit  uart_trans_finished;                       // 串口发送完成标志,表示串口处于发送空闲状态
  66          
  67          unsigned char uart_receive_buf[250];    // 接收缓冲区
  68          unsigned char uart_trans_buf[250];              // 发送缓冲区
  69          unsigned char uart_trans_count;                 // 发送数据计数器
  70          unsigned char uart_receive_count;               // 接收的数据计数器
  71          unsigned char uart_trans_length;                // 将要发送的数据长度
  72          
  73          unsigned char run_count; 
  74          
  75          unsigned char uart_char_space;          // 串口帧内间隔计数器(10ms) 最大为60ms
  76          unsigned char  uart_frame_space;        // 串口帧间间隔计数器(10ms) 最小为80ms
  77          unsigned char  data dog;                                        // 看门狗计数器(10ms)  最大为120 ms
  78          #define clear_watchdog() watch_dog=1; _nop_();_nop_();_nop_();_nop_();dog=0;watch_dog=0  
  79          bit being_echo;                                 // 网络要求远端返回数据标志,表示要判断网络超时
  80          bit remote_echo;
  81          bit first_arp; 
  82          unsigned int   net_overtime_count;  // 网络发送超时计数器
  83          
  84          //ETHERFRAME etherframe;
  85          //NODE  locnode;                      /* My Ethernet and IP addresses */
  86          //NODE  remnode;                       /* Remote node */
  87          
  88          //extern BYTE mymac[MACLEN];                    //  该变量为ethernet.c 用源地址mac
  89          void system_init(void);
  90          void flush_gate_mac();
  91          void do_uart_process(void);
  92          int do_net_process(ETHERFRAME *efp,int rxlen);
*** ERROR C141 IN LINE 92 OF MAIN.C: syntax error near '*', expected ')'
  93          int udp_receive(ETHERFRAME *efp, int len);
*** ERROR C141 IN LINE 93 OF MAIN.C: syntax error near '*', expected ')'
  94          void send_ip(void);
  95          unsigned long runtime;
  96          void system_init(void)
  97          {
  98   1              EA=0;                   
*** ERROR C202 IN LINE 98 OF MAIN.C: 'EA': undefined identifier
  99   1              SCON=0xD2;                                      // SM0,SM1,SM2,REN,TB,RB,TI,RI 
*** ERROR C202 IN LINE 99 OF MAIN.C: 'SCON': undefined identifier
 100   1                                                                      // 9位数据位,一位停止位,允许串行中断 
 101   1              PCON=0x80;                      // SMOD=1, 波特率加倍
*** ERROR C202 IN LINE 101 OF MAIN.C: 'PCON': undefined identifier
 102   1              TMOD=0x21;                      // GATE  C/T M1 M0 GATE C/T M1 M0 
*** ERROR C202 IN LINE 102 OF MAIN.C: 'TMOD': undefined identifier
 103   1                                              // 定时器1在自动装入方式,0 位16位方式
 104   1              TCON=0x50;                      // TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
*** ERROR C202 IN LINE 104 OF MAIN.C: 'TCON': undefined identifier
 105   1                                                      // 定时器运行状态,不允许外部中断
 106   1              TH1=BPS4800;
*** ERROR C202 IN LINE 106 OF MAIN.C: 'TH1': undefined identifier
 107   1              TL1=BPS4800;
*** ERROR C202 IN LINE 107 OF MAIN.C: 'TL1': undefined identifier
 108   1              TH0=HIGH(timer_10ms_value);                                     //16位10ms 定时器
C51 COMPILER V7.50   MAIN                                                                  08/13/2006 23:44:28 PAGE 3   

*** ERROR C202 IN LINE 108 OF MAIN.C: 'TH0': undefined identifier
 109   1              TL0=LOW(timer_10ms_value);
*** ERROR C202 IN LINE 109 OF MAIN.C: 'TL0': undefined identifier
 110   1      //      IE=0x92;                                // EA ?  ? ES ET1 EX1 ET0 EX0   
 111   1      //      IP=0x02;
 112   1              clear_watchdog();
 113   1      }
 114          
 115          
 116          void main(void)
 117          {
 118   1              int rxlen;
 119   1              int ret;
 120   1      //      unsigned char temp[6];
 121   1      //      clear_watchdog();
 122   1              delay_ms(2);
 123   1              system_init();                          //设置单片机的定时器 T0 (10ms),及 串口的波特率4800bps
 124   1              while (1)
 125   1              {
 126   2              }
 127   1      }               
 128          /*************************************************************************/
 129          // 通过计数器uart_char_space 判断串口60MS没有新数据到达就认为一帧数据接收完成
 130          // 在网络要求远端返回数据状态下,网络超时计数器加 1(10ms)
 131          /*************************************************************************/
 132          
 133          void timer0_interrupt(void)  interrupt 1
 134          {
 135   1              TL0=TL0+LOW(timer_10ms_value);                          //reload timer0
 136   1              TH0=TH0+HIGH(timer_10ms_value);
 137   1      
 138   1              run_count++;
 139   1              if(run_count>100)
 140   1              {
 141   2                      run_count=0;
 142   2                      run_led=~run_led;
 143   2              }
 144   1      
 145   1              if (uart_receiving)
 146   1              {
 147   2                      if (uart_char_space<6)
 148   2                              uart_char_space++;
 149   2                      else
 150   2                      {
 151   3                              uart_receiving=false;
 152   3                              uart_receive_enable=false;
 153   3                              uart_received_finished=true;
 154   3                              uart_frame_space=0;
 155   3                      }
 156   2                      uart_frame_space=0;
 157   2              }
 158   1              else
 159   1              {
 160   2                      if (!uart_receive_enable)
 161   2                      {
 162   3                              uart_frame_space++;
 163   3                              if (uart_frame_space>8)
 164   3                              {
 165   4                                      uart_frame_space=0;
 166   4                                      uart_receive_enable=true;
 167   4                              }
 168   3                       }
C51 COMPILER V7.50   MAIN                                                                  08/13/2006 23:44:28 PAGE 4   

 169   2              }
 170   1              if (uart_trans_willing)
 171   1              {
 172   2                              uart_trans_willing=false;
 173   2                              TI=1;
 174   2              }
 175   1              
 176   1          if (being_echo)
 177   1          {
 178   2                   net_overtime_count++;
 179   2                   if (net_overtime_count>18000)
 180   2                   {
 181   3                      being_echo=0;
 182   3                      if (first_arp)
 183   3                              first_arp=0;
 184   3                      else    
 185   3                              remote_echo=1;
 186   3                      net_overtime_count=0;
 187   3                   }
 188   2          }           
 189   1              runtime++;
 190   1              dog++;
 191   1      }
 192          
 193          /*************************************************************************/
 194          //    串口中断程序,该程序在认为串口的接收是终端在响应串口的发送
 195          //    在串口未发送完成之前,不处理完罗接收的数据
 196          /*************************************************************************/
 197          void uart_interrupt(void)  interrupt 4 
 198          {
 199   1              if (RI)
 200   1              {
 201   2                      RI=0;
 202   2                      if ((!uart_received_finished)&& uart_receive_enable)
 203   2                      {
 204   3                              if (!uart_receiving)
 205   3                              {
 206   4                                      uart_receiving=1;
 207   4                                      uart_receive_count=0;
 208   4                                      uart_receive_buf[uart_receive_count++]=SBUF;
 209   4                              }
 210   3                              else
 211   3                              {
 212   4                                      uart_char_space=0;
 213   4                                      uart_receive_buf[uart_receive_count++]=SBUF;
 214   4                              }
 215   3                      }
 216   2              }
 217   1              if (TI)
 218   1              {
 219   2                      TI=0;
 220   2                      if (uart_trans_count<uart_trans_length)
 221   2                      {
 222   3                                      ACC=uart_trans_buf[uart_trans_count++];
 223   3                                      TB8=P;
 224   3                                      SBUF=ACC;
 225   3                      }
 226   2                      else
 227   2                      {
 228   3                                      uart_trans_finished=1;
 229   3                                      uart_trans_count=0;
 230   3                                      uart_trans_length=0;
C51 COMPILER V7.50   MAIN                                                                  08/13/2006 23:44:28 PAGE 5   

 231   3                      }
 232   2                                      
 233   2              }
 234   1      }
 235          

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

⌨️ 快捷键说明

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