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

📄 _485_funcs.lst

📁 CAN工业节点设计、CAN控制器为SJA1000.C源码
💻 LST
字号:
C51 COMPILER V8.09   _485_FUNCS                                                            03/13/2008 06:00:59 PAGE 1   


C51 COMPILER V8.09, COMPILATION OF MODULE _485_FUNCS
OBJECT MODULE PLACED IN _485_funcs.OBJ
COMPILER INVOKED BY: E:\Keil\C51\BIN\C51.EXE _485_funcs.c ROM(COMPACT) BROWSE INCDIR(E:\Keil\C51\INC) DEBUG OBJECTEXTEND

line level    source

   1          #include "xkcan_defs.h"
   2          #include "_485_defs.h"
   3          #include <regx52.h>
   4          
   5          _t_485_tuoke_dh4_rx     idata rx485FrameTemp;
   6          ubyte *                         idata pRx485Frame;
   7          ubyte                           idata iRx485Frame;
   8          
   9          _t_485_tuoke_dh4        idata tx485FrameTemp;
  10          ubyte *                         idata pTx485Frame;
  11          ubyte                           idata iTx485Frame;
  12          
  13          
  14          /*unsigned int CRC(unsigned char *Buff,unsigned char Len)
  15          {
  16                  unsigned char i,j;
  17                  unsigned char crc[2];
  18                  crc[1]=0xff;                    //Upper
  19                  crc[0]=0xff;                    //Lower
  20                  for(i=0;i<Len;i++)
  21                  {
  22                          crc[0] = crc[0] ^ Buff[i];
  23                                  for(j=0;j<8;j++)
  24                          {
  25                                  if((crc[0] & 0x01 )== 0x01 )
  26                                  {
  27                                          if((crc[1] & 0x01) == 0x01)
  28                                          {
  29                                                  crc[0] >>=1;
  30                                                  crc[0] |= 0x80;
  31                                                  crc[1] >>=1;
  32                                          }
  33                                          else
  34                                          {
  35                                                  crc[0] >>=1;
  36                                                  crc[1] >>=1;
  37                                          }
  38                                          crc[1] ^= 0xA0;
  39                                          crc[0] ^= 0x01;
  40                                  }
  41                                  else
  42                                  {
  43                                          if((crc[1] & 0x01) == 0x01)
  44                                          {
  45                                                  crc[0] >>=1;
  46                                                  crc[0] |= 0x80;
  47                                                  crc[1] >>=1;
  48                                          }
  49                                          else
  50                                          {
  51                                                  crc[0] >>=1;
  52                                                  crc[1] >>=1;
  53                                          }
  54                                  }
  55                          }
C51 COMPILER V8.09   _485_FUNCS                                                            03/13/2008 06:00:59 PAGE 2   

  56                  }
  57                  return crc[1]*0x100+crc[0];
  58          } */
  59          
  60          void _485_Tuoke_DH4_CRC(ubyte * buff)
  61          {
  62   1              ushort i, j;
  63   1              uint crc;
  64   1              
  65   1              crc = 0xffff;
  66   1      
  67   1              for ( i = 0; i < 5; i ++ )
  68   1              {
  69   2                      crc = crc ^ (int)(buff[i]);
  70   2      
  71   2                      for (j = 0; j < 8; j ++ )
  72   2                      {
  73   3                              if ( (crc & 0x01) == 0x01 )
  74   3                              {
  75   4                                      crc >>= 1;
  76   4                                      crc ^= 0xA001;
  77   4                              }
  78   3                              else
  79   3                              {
  80   4                                      crc >>= 1;
  81   4                              }
  82   3                      }
  83   2              }
  84   1              *(buff+6) = *(ubyte*)(&crc);
  85   1              *(buff+5) = *((ubyte*)(&crc) + 1);
  86   1      }
  87          
  88          ubyte _485_Tuoke_DH4_CRCCheck(ubyte * buff)
  89          {
  90   1              ushort i, j;
  91   1              uint crc;
  92   1              
  93   1              crc = 0xffff;
  94   1      
  95   1              for ( i = 0; i < 5; i ++ )
  96   1              {
  97   2                      crc = crc ^ (int)(buff[i]);
  98   2      
  99   2                      for (j = 0; j < 8; j ++ )
 100   2                      {
 101   3                              if ( (crc & 0x01) == 0x01 )
 102   3                              {
 103   4                                      crc >>= 1;
 104   4                                      crc ^= 0xA001;
 105   4                              }
 106   3                              else
 107   3                              {
 108   4                                      crc >>= 1;
 109   4                              }
 110   3                      }
 111   2              }
 112   1              if (( *(buff+6) == *(ubyte*)(&crc) ) && (*(buff+5) == *((ubyte*)(&crc) + 1)) )
 113   1                      return 1;
 114   1              else 
 115   1                      return 0;
 116   1      }
 117          
C51 COMPILER V8.09   _485_FUNCS                                                            03/13/2008 06:00:59 PAGE 3   

 118          
 119          ubyte _485_GenerateReadFrame(ubyte stntype, ubyte stn, void * pFrame)
 120          {
 121   1              if (stntype == INSTR_TUOKE_DH4)
 122   1              {
 123   2                      ((_t_485_tuoke_dh4 *)pFrame)->stn       = stn;
 124   2                      ((_t_485_tuoke_dh4 *)pFrame)->pre[0]= INSTR_TUOKE_DH4_TX_PRE;
 125   2                      ((_t_485_tuoke_dh4 *)pFrame)->pre[1]= INSTR_TUOKE_DH4_TX_PRE;
 126   2                      ((_t_485_tuoke_dh4 *)pFrame)->pre[2]= INSTR_TUOKE_DH4_TX_PRE;
 127   2                      ((_t_485_tuoke_dh4 *)pFrame)->fc        = INSTR_TUOKE_DH4_READ_DATA;
 128   2                      ((_t_485_tuoke_dh4 *)pFrame)->addr      = INSTR_TUOKE_DH4_ADDR_DATA;
 129   2                      ((_t_485_tuoke_dh4 *)pFrame)->dat_L     = 0x00;
 130   2                      ((_t_485_tuoke_dh4 *)pFrame)->dat_H     = 0x00;
 131   2                      ((_t_485_tuoke_dh4 *)pFrame)->CRC_L     = 0x00;
 132   2                      ((_t_485_tuoke_dh4 *)pFrame)->CRC_H     = 0x00;
 133   2      
 134   2                      ((_t_485_tuoke_dh4 *)pFrame)->suf       = INSTR_TUOKE_DH4_TX_SUF;
 135   2                      
 136   2                      _485_Tuoke_DH4_CRC((ubyte *)pFrame + 3);
 137   2              }
 138   1              else
 139   1              {
 140   2                      //TODO: Add codes support other types of intelligent instruments.
 141   2                      //              Define the STNTYPE in _485_defs.h
 142   2                      //              Define the struct _t_485_xxxx for the specific instrument.
 143   2              }
 144   1              return 0;
 145   1      }
 146          
 147          ubyte _485_Init()
 148          {
 149   1      
 150   1              SCON =  0x50;           // uart in mode 1 (8 bit), REN=1 
 151   1              TMOD =  0x20 ;          // Timer 1 in mode 2 
 152   1              PCON |= 0x80;           // SMOD1 = 1 
 153   1              TH1     = 0xF3;                 // 9600 Bds at 24MHz 
 154   1              TL1     = 0xF3;                 // 9600 Bds at 24MHz 
 155   1              ES      = 1;                    // Enable serial interrupt      
 156   1              TR1 = 1;                        // Timer 1 run 
 157   1              
 158   1              pRx485Frame = (ubyte *) &rx485FrameTemp;
 159   1              iRx485Frame = 0;
 160   1              pTx485Frame = (ubyte *) &tx485FrameTemp;
 161   1              iTx485Frame = 0;
 162   1      
 163   1      
 164   1              return 0;
 165   1      }
 166          
 167          void _485_SendData(ubyte stntype)
 168          {
 169   1              if ( flag_uart_txc == 1 && flag_485_tx == 1 )
 170   1              {
 171   2                      flag_uart_txc = 0;
 172   2                      SBUF = *pTx485Frame++;
 173   2                      iTx485Frame++;
 174   2                      if (stntype == INSTR_TUOKE_DH4)
 175   2                      {
 176   3                              if ( iTx485Frame == INSTR_TUOKE_DH4_FRAME_LEN)
 177   3                              {
 178   4                                      // If all were sent, clear flag_uart_send
 179   4                                      iTx485Frame = 0;
C51 COMPILER V8.09   _485_FUNCS                                                            03/13/2008 06:00:59 PAGE 4   

 180   4                                      pTx485Frame = (ubyte *) &tx485FrameTemp;
 181   4                                      flag_485_tx = 0;
 182   4                              }
 183   3                      }
 184   2              }
 185   1      }
 186          
 187          ubyte _485_ReceiveData()
 188          {
 189   1              ubyte stntype;
 190   1              if ( flag_uart_rcv == 1 )       
 191   1              {
 192   2                      flag_uart_rcv = 0;
 193   2      
 194   2              ////////////////////////////////////////////////////////////////////
 195   2              // Here, the code is written for Tuoke DH4 inteligent instruments
 196   2              // If there're several kinds of instruments connected to the 485 bus,
 197   2              // Codes to determine who sent the data should be added here!!!!!!
 198   2      
 199   2                      if (iRx485Frame < 3)
 200   2                      {       // Check the prefix
 201   3                              if (uart_data == INSTR_TUOKE_DH4_RX_PRE)
 202   3                                      iRx485Frame++;
 203   3                              else
 204   3                                      iRx485Frame = 0;
 205   3                      }
 206   2                      else if (iRx485Frame < 10)
 207   2                      {       // Prefix is fine, receive data
 208   3                              iRx485Frame++;
 209   3                              *pRx485Frame++ = uart_data;
 210   3                      }
 211   2                      else if (uart_data == INSTR_TUOKE_DH4_RX_SUF) 
 212   2                      {       // Check the suffix
 213   3                              flag_485_rcv = 1;
 214   3                              pRx485Frame = (ubyte *) &rx485FrameTemp;
 215   3                              iRx485Frame = 0;
 216   3                      }
 217   2                      else
 218   2                      {       // 
 219   3                              iRx485Frame = 0;
 220   3                              pRx485Frame = (ubyte *) &rx485FrameTemp;
 221   3                      }
 222   2              ////////////////////////////////////////////////////////////////////////
 223   2              //      Code samples to determin the station type
 224   2              ////////////////////////////////////////////////////////////////////////
 225   2              //      if (blabla)
 226   2              //      {
 227   2                      stntype = INSTR_TUOKE_DH4;
 228   2                      return stntype;
 229   2              //      }
 230   2      
 231   2              ////////////////////////////////////////////////////////////////////////
 232   2      
 233   2              }
 234   1      }
 235          
 236                  


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    501    ----
   CONSTANT SIZE    =   ----    ----
C51 COMPILER V8.09   _485_FUNCS                                                            03/13/2008 06:00:59 PAGE 5   

   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      10
   IDATA SIZE       =     26    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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