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

📄 can.lst

📁 该程序完成了c8051外围电路的驱动和串口协议的编写。希望能给大家学习51单片机带来帮助
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.10   CAN                                                                   09/18/2008 14:09:31 PAGE 1   


C51 COMPILER V7.10, COMPILATION OF MODULE CAN
OBJECT MODULE PLACED IN can.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 20progress\can.c BROWSE DEBUG OBJECTEXTEND PRINT(.\can.lst) OBJECT(can.obj)

line level    source

   1          #include "can.h"
   2          
   3          unsigned char xdata uchDataRecBuf[8][250];    //收到的数据
   4          unsigned char idata uchDataRecBufIndex=0;            //缓冲区中包数
   5          unsigned char idata uchReadDataRecBufIndex=0;             //读取数据的包指针
   6          unsigned char  uchRePID;
   7          unsigned char uchReDesID;
   8          unsigned char xdata uchReSendDataBuf[300];
   9          unsigned char idata uchFrameRotateIndex = 0;
  10          unsigned char uchInforBagNum = 0xFF;
  11          unsigned char idata uchCanAddress;
  12          
  13          //--------------------------------------------------------------------------------------------------
  14          //函数名称:void CANModuleParaInit(void)
  15          //功    能:初始化CAN模块的参数
  16          //输入参数:无
  17          //返    回:无                                           
  18          //完成日期:4/13/2007
  19          //-------------------------------------------------------------------------------------------------
  20          void CANModuleParaInit(void)                       //tong add
  21          {
  22   1              uchCanAddress = ReadCANAddress();
  23   1      } 
  24          
  25          /////////////////////////////////////////////////////////////////////////////////////////
  26          //void SendPackage(unsigned char pID, unsigned char desID, unsigned char* SendData)
  27          //入口参数:pID:事件类型,desID:目的地址,*SendData:发送数据包       
  28          //函数返回:无
  29          //全局变量:souID:源地址,从插槽上读出的数据
  30          //功能描述:把要解决的问题整理为数据,等候发送
  31          //函数说明:如果发送失败,长度不对
  32          //编写人:  郑福
  33          //编写完成时间: 2007-04-20
  34          //修改人:
  35          //修改完成时间:
  36          //修改原因:                                                
  37          /////////////////////////////////////////////////////////////////////////////////////////
  38          void SendPackage(unsigned char pID, unsigned char desID, unsigned char* SendData)
  39          {
  40   1              unsigned char idata uchValue;
  41   1              unsigned char idata uchResponFlag;
  42   1              unsigned char idata uchSouID;
  43   1              unsigned char idata uchMsgLength;
  44   1              unsigned char idata uchFrameNum;
  45   1              unsigned char idata uchResidByteNum;
  46   1              unsigned char idata uchCycIndex,uchSendi,uchSendj;
  47   1              unsigned char idata uchFrameFlag;
  48   1              unsigned char xdata uchRemotAndData[13];
  49   1              unsigned char idata uchDesID = desID;
  50   1              unsigned int idata uii;
  51   1              unsigned int idata uchSendNum;
  52   1          unsigned char idata uchFrameIndex = 0;
  53   1      
  54   1          LEDConfigControl();
  55   1              
C51 COMPILER V7.10   CAN                                                                   09/18/2008 14:09:31 PAGE 2   

  56   1              uchRePID = pID;
  57   1          uchReDesID = desID;
  58   1              for (uii=0; uii<((SendData[1]<<8 | SendData[2])+3); uii++)
  59   1              {
  60   2                      uchReSendDataBuf[uii] = SendData[uii];
  61   2              }
  62   1      
  63   1      //      read_TRX_error();
  64   1      
  65   1      
  66   1               uchInforBagNum++;
  67   1          if(uchInforBagNum >= 8)
  68   1          {
  69   2                      uchInforBagNum = 0;
  70   2              }
  71   1              if ((SendData[1] == 0x00)&&(SendData[2] == 0x00))
  72   1              {
  73   2                      uchRemotAndData[0]= 0xc0;           //远程帧
  74   2                      uchRemotAndData[1] = 0x44 | pID; 
  75   2                      desID = 0xc0 | desID;    // 0xc0 = 0x03<<6;  11只有一帧
  76   2                      uchRemotAndData[2]= desID;
  77   2                      uchSouID = uchCanAddress;
  78   2                      uchResponFlag = SendData[0]<<6;             
  79   2                      uchSouID = uchResponFlag | uchSouID;
  80   2                      uchRemotAndData[3]= uchSouID; 
  81   2      //              uchRemotAndData[4]= 0x00;
  82   2                      uchRemotAndData[4] =  (uchInforBagNum<<3) & 0x3C;        //bagNum and 0frame
  83   2                      uchRemotAndData[5]= '\0';
  84   2                      uchRemotAndData[6]= '\0';
  85   2                      uchRemotAndData[7]= '\0';
  86   2                      uchRemotAndData[8]= '\0';
  87   2                      uchRemotAndData[9]= '\0';
  88   2                      uchRemotAndData[10]= '\0';
  89   2                      uchRemotAndData[11]= '\0';
  90   2                      uchRemotAndData[12]= '\0';
  91   2                      writeCANdata(uchRemotAndData);
  92   2              }
  93   1              else                                  //CAN数据帧打包开始
  94   1              {
  95   2                      uchSendNum = ((SendData[1]<<8) + SendData[2]);
  96   2                      uchFrameNum = uchSendNum/8;       //帧数
  97   2                      uchResidByteNum = uchSendNum%8;   //不够一帧的字节数
  98   2              
  99   2                      for (uchCycIndex=0; uchCycIndex<=uchFrameNum; uchCycIndex++)
 100   2                      {
 101   3                              if (uchFrameNum == uchCycIndex)
 102   3                              {
 103   4                                      if (uchResidByteNum==0x00)
 104   4                                      {
 105   5                                              break;
 106   5                                      }
 107   4                                      else 
 108   4                                      {
 109   5                                              if (uchResidByteNum!=0x00 && uchFrameNum==0)
 110   5                                              {
 111   6                                                      uchMsgLength = uchResidByteNum;
 112   6                                                      uchFrameFlag = 0x03;//0x03只有一帧  
 113   6                                              }
 114   5                                              else
 115   5                                              {
 116   6                                                      uchMsgLength = uchResidByteNum;
 117   6                                                      uchFrameFlag = 0x02; // 10  最后一帧
C51 COMPILER V7.10   CAN                                                                   09/18/2008 14:09:31 PAGE 3   

 118   6                                              }
 119   5                                      }
 120   4                              }
 121   3                              else 
 122   3                              {
 123   4                                      uchMsgLength = 0x08;
 124   4                                      if (uchCycIndex == 0x00) 
 125   4                                      {
 126   5                                              if ((uchResidByteNum==0x00)&&(uchFrameNum==0x01))
 127   5                                              {
 128   6                                                      uchFrameFlag = 0x03;     //0x03只有一帧
 129   6                                              }
 130   5                                              else 
 131   5                                              {
 132   6                                                      uchFrameFlag = 0x00;    // 00 起始帧
 133   6                                              }
 134   5                                      }
 135   4                                      else 
 136   4                                      {
 137   5                                              if ((uchResidByteNum==0x00)&&((uchFrameNum-1)==uchCycIndex))
 138   5                                              {
 139   6                                                      uchFrameFlag = 0x02; // 10  最后一帧
 140   6                                              }
 141   5                                              else 
 142   5                                              {
 143   6                                                      uchFrameFlag = 0x01;// 01 中间帧
 144   6                                              }
 145   5                                      }
 146   4                              }
 147   3      
 148   3              uchValue = 0x80 + uchMsgLength;// Bit7=1:EFF;Bit6=0:data 
 149   3              uchRemotAndData[0] = uchValue;  
 150   3              uchRemotAndData[1] =  0x44 | pID;   
 151   3              desID = (uchFrameFlag<<6) | uchDesID;
 152   3              uchRemotAndData[2] = desID;     
 153   3      
 154   3              uchSouID = uchCanAddress;
 155   3              uchResponFlag = SendData[0]<<6;             
 156   3              uchSouID = uchResponFlag | uchSouID;
 157   3              uchRemotAndData[3] = uchSouID;   
 158   3              uchRemotAndData[4] = (uchFrameIndex<<6 | uchInforBagNum<<3);    
 159   3              uchFrameIndex++;
 160   3      
 161   3              if(uchFrameIndex == 0x04)
 162   3              {
 163   4                      uchFrameIndex = 0;
 164   4              }
 165   3              
 166   3              if (0x08 == uchMsgLength)
 167   3              {
 168   4                      uchRemotAndData[5] = SendData[uchCycIndex*8+3];
 169   4                      uchRemotAndData[6] = SendData[uchCycIndex*8+4];
 170   4                      uchRemotAndData[7] = SendData[uchCycIndex*8+5];
 171   4                      uchRemotAndData[8] = SendData[uchCycIndex*8+6];
 172   4                      uchRemotAndData[9] = SendData[uchCycIndex*8+7];
 173   4                      uchRemotAndData[10] = SendData[uchCycIndex*8+8];
 174   4                      uchRemotAndData[11] = SendData[uchCycIndex*8+9];
 175   4                      uchRemotAndData[12] = SendData[uchCycIndex*8+10];
 176   4              }
 177   3              else 
 178   3              {
 179   4                      uchSendj = 0x00;
C51 COMPILER V7.10   CAN                                                                   09/18/2008 14:09:31 PAGE 4   

 180   4                      for (uchSendi=0; uchSendi<uchMsgLength; uchSendi++)
 181   4                      {
 182   5                              uchRemotAndData[5+uchSendi] = SendData[uchCycIndex*8+3+uchSendi];
 183   5                              uchSendj++;
 184   5                      }                               
 185   4                      for (uchSendi=uchSendj; uchSendi<0x08; uchSendi++)
 186   4                      {
 187   5                              uchRemotAndData[5+uchSendi] = '\0';
 188   5                      }
 189   4                      uchFrameIndex = 0;                      
 190   4              }
 191   3              
 192   3              writeCANdata(uchRemotAndData);
 193   3                      
 194   3              if (SendData[0] == 0x01)
 195   3              {
 196   4                      if(uchCycIndex == 0x00) 
 197   4                      {
 198   5      //                      CAN_ReSendSetInitia(20);    //启动发送超时定时器4单位是(ms)
 199   5                      }
 200   4                      else 
 201   4                      {
 202   5      //                      CAN_ReSendReVal(20);       //重写超时定时器4
 203   5                      }
 204   4              }       
 205   3                      } //for(uchCycIndex=0; uchCycIndex<=uchFrameNum; uchCycIndex++)结束
 206   2              } //CAN数据帧打包结束
 207   1      
 208   1              LEDConfigControl();
 209   1      }
 210          void SendPackageRemoteFrame(unsigned char pID, unsigned char  desID, unsigned char  *SendData)
 211          {
 212   1      
 213   1              unsigned char uchResponFlag;
 214   1              unsigned char uchSouID; 
 215   1          unsigned char uchCycIndexCopy = 0;
 216   1              unsigned char uchPackIndex = 0;
 217   1              unsigned char xdata uchRemotAndData[5];
 218   1              unsigned char uchDesID = desID;
 219   1      
 220   1      
 221   1          uchRePID = pID;
 222   1          uchReDesID = desID;
 223   1              
 224   1              uchInforBagNum++;
 225   1          if(uchInforBagNum >= 8)
 226   1          {
 227   2                      uchInforBagNum = 0;
 228   2              }
 229   1      
 230   1              uchRemotAndData[0]= 0xc0;           //远程帧
 231   1              uchRemotAndData[1] = 0x44 | pID; 
 232   1              desID = 0xc0 | desID;    // 0xc0 = 0x03<<6;  11只有一帧
 233   1              uchRemotAndData[2]= desID;
 234   1              uchSouID = uchCanAddress;
 235   1              uchResponFlag = SendData[0]<<6;             
 236   1              uchSouID = uchResponFlag | uchSouID;
 237   1              uchRemotAndData[3]= uchSouID; 
 238   1              uchRemotAndData[4] =  (uchInforBagNum<<3) & 0x3C;        //bagNum and 0frame

⌨️ 快捷键说明

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