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

📄 comm.lst

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


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

line level    source

   1          //*******************************************************************************
   2          //Copyright (c) 2007,派利斯电子(北京)有限公司 硬件部
   3          //文件名称: comm.c
   4          //摘    要: 本文件主要包含通信解析部分的程序
   5          //当前版本: D-1 
   6          //作    者:  佟文杰
   7          //完成日期: 4/16/2007
   8          //修 改 人:
   9          //修改原因:
  10          //修改日期:
  11          //*******************************************************************************
  12          #include <string.h>
  13          #include "comm.h"
  14          #include "framemodule.h"
  15          
  16          extern xdata union para1 All;
  17          
  18          unsigned char  xdata  *pInput;
  19          xdata struct System *pOutput;
  20          unsigned char  xdata  uchSendBuf[100];
  21          unsigned char xdata uchAlarmStatusJudge[2];
  22          unsigned char xdata uchAlarmStatusJudgeBAK[2];
  23          unsigned char xdata uchModuleConfigStatus;
  24          unsigned char xdata uchCPUAddressStatus;
  25          
  26          unsigned int xdata uiForeChannelType; //20080529
  27          
  28          //--------------------------------------------------------------------
  29          //函数名称:void CanMessageProcess(void)
  30          //功    能:处理CAN命令包
  31          //输入参数:无
  32          //返    回:无
  33          //完成日期:4/16/2007
  34          //--------------------------------------------------------------------
  35          void CanMessageProcess(void)
  36          {
  37   1              unsigned int idata i,uiOffset,uiLength;
  38   1              unsigned char  xdata  *p;
  39   1              static unsigned char xdata uchCalibrationStatus = 2;  //0:标定零点 1:标定满度  2:初始值无意义
  40   1      
  41   1              FeedDog();                                                                                                
  42   1              pOutput = (struct System  *)&All;                                         
  43   1              i = BagNum();
  44   1              while(i--)
  45   1              {
  46   2                      pInput = GetAMessage();
  47   2                      if(pInput == NULL)
  48   2                      {
  49   3                              return;
  50   3                      }
  51   2                      switch(pInput[3])
  52   2                      {
  53   3                              case READ_MODULE_PARAMETERS:                      //0x01
  54   3                                      if (((uchCPUAddressStatus == 0) && (pInput[4] == 1 || pInput[4] == 2)) 
C51 COMPILER V7.10   COMM                                                                  09/18/2008 14:09:30 PAGE 2   

  55   3                                                      || ((uchCPUAddressStatus == 1) && (pInput[4] == 3 || pInput[4] == 4)))
  56   3                                      {
  57   4                                              uchSendBuf[0] = 0;
  58   4                                              uiOffset = *((unsigned int *)&pInput[5]);
  59   4                                              uiLength = *((unsigned int *)&pInput[7]);
  60   4                                              uiLength = uiLength*2;
  61   4                                              uchSendBuf[1] = (uiLength+6)/256;       
  62   4                                              uchSendBuf[2] = (uiLength+6)%256;
  63   4                                              uchSendBuf[3] = 0x02;
  64   4                                              uchSendBuf[4] = pInput[4];
  65   4                                              *((unsigned int *)&uchSendBuf[5]) = uiOffset;
  66   4                                              *((unsigned int *)&uchSendBuf[7]) = uiLength/2; 
  67   4              
  68   4                                              if ((uiOffset >= 40200) && (uiOffset <= 40237))
  69   4                                              {
  70   5                                                      uiOffset = AddrMap(uiOffset);                                      
  71   5                                                      if(pInput[4] == 1 || pInput[4] == 2)
  72   5                                                      {
  73   6                                                              p = (unsigned char  xdata *)&pOutput->Ch[0x1&(pInput[4] - 1)]+uiOffset*2;
  74   6                                                              memcpy((unsigned char*)&uchSendBuf[9],p,uiLength);
  75   6                                                      }
  76   5                      
  77   5                                                      if(pInput[4] == 3 || pInput[4] == 4)
  78   5                                                      {
  79   6                                                              p = (unsigned char  xdata *)&pOutput->Ch[0x1&(pInput[4] - 3)]+uiOffset*2;
  80   6                                                              memcpy((unsigned char*)&uchSendBuf[9],p,uiLength);
  81   6                                                      }
  82   5                                              } 
  83   4                                              else if (uiOffset == 40251)
  84   4                                              {
  85   5                                                      if (pInput[4] == 1 || pInput[4] == 2)
  86   5                                                      {
  87   6                                                              if (uiLength == 2)
  88   6                                                              {
  89   7                                                                      *(unsigned int *)&uchSendBuf[9] = *(unsigned int xdata *)&pOutput->uiTripValue[pInput[4] - 1];
  90   7                                                              }
  91   6                                                              else if (uiLength == 4)
  92   6                                                              {
  93   7                                                                      *(unsigned int *)&uchSendBuf[9] = *(unsigned int xdata *)&pOutput->uiTripValue[pInput[4] - 1];
  94   7                                                                      *(unsigned int *)&uchSendBuf[11] = *(unsigned int xdata *)&pOutput->uiBypassFlag[pInput[4] - 1];
  95   7                                                              }
  96   6                                                      }
  97   5                                                      else if (pInput[4] == 3 || pInput[4] == 4)
  98   5                                                      {
  99   6                                                              if (uiLength == 2)
 100   6                                                              {
 101   7                                                                      *(unsigned int *)&uchSendBuf[9] = *(unsigned int xdata *)&pOutput->uiTripValue[pInput[4] - 3];
 102   7                                                              }
 103   6                                                              else if (uiLength == 4)
 104   6                                                              {
 105   7                                                                      *(unsigned int *)&uchSendBuf[9] = *(unsigned int xdata *)&pOutput->uiTripValue[pInput[4] - 3];
 106   7                                                                      *(unsigned int *)&uchSendBuf[11] = *(unsigned int xdata *)&pOutput->uiBypassFlag[pInput[4] - 3];
 107   7                                                              }
 108   6                                                      }
 109   5                                              }
 110   4                                              else if (uiOffset == 40252)
 111   4                                              {
 112   5                                                      if (pInput[4] == 1 || pInput[4] == 2)
 113   5                                                      {
 114   6                                                              *(unsigned int *)&uchSendBuf[9] = *(unsigned int xdata *)&pOutput->uiBypassFlag[pInput[4] - 1];
 115   6                                                      }
 116   5                                                      else if (pInput[4] == 3 || pInput[4] == 4)
C51 COMPILER V7.10   COMM                                                                  09/18/2008 14:09:30 PAGE 3   

 117   5                                                      {
 118   6                                                              *(unsigned int *)&uchSendBuf[9] = *(unsigned int xdata *)&pOutput->uiBypassFlag[pInput[4] - 3];
 119   6                                                      }       
 120   5                                              }
 121   4                                              SendPackage(0,1,uchSendBuf);
 122   4                                      }
 123   3                                      break;
 124   3      
 125   3                              case READ_MODULE_INFO:                             //0x03          读模块相关信息
 126   3                                      if (uchCPUAddressStatus == 0)
 127   3                                      {
 128   4                                              uchSendBuf[0] = 0;
 129   4                                              uiOffset = *((unsigned int *)&pInput[4]);
 130   4                                              uiLength = *((unsigned int *)&pInput[6]);
 131   4                                              uiLength = uiLength*2;
 132   4                                              uchSendBuf[1] = (uiLength+5)/256;
 133   4                                              uchSendBuf[2] = (uiLength+5)%256;
 134   4                                              uchSendBuf[3] = 0x04;
 135   4      
 136   4                                              *((unsigned int *)&uchSendBuf[4]) = *((unsigned int *)&pInput[4]);
 137   4                                              *((unsigned int *)&uchSendBuf[6]) = *((unsigned int *)&pInput[6]);
 138   4                                              p = (unsigned char  xdata *)&pOutput->Info+(uiOffset-40191)*2;
 139   4                                              memcpy((unsigned char*)&uchSendBuf[8],p,uiLength);
 140   4                                              (unsigned int)uchSendBuf[8] = 403;          
 141   4                                              SendPackage(3,1,uchSendBuf);
 142   4                                      }
 143   3                                      break;
 144   3      
 145   3                              case READ_CURRENT_STATUS:                               //0x05
 146   3      
 147   3                                      break;
 148   3      
 149   3                              case SET_FULL_SCALE:                                      //0x0b
 150   3                                      pOutput->iDataSpan = *((int*)&pInput[4]);                               
 151   3                                      WriteSystemPara(0,(unsigned char xdata *)pOutput, PARALENGTH*2); // flash module
 152   3                                      SetFullScale(*((int*)&pInput[4]));
 153   3                                      break;
 154   3      
 155   3                              case READ_FULL_SCALE:                                    //0x0c
 156   3                                      uchSendBuf[0] = 0;
 157   3                                      uchSendBuf[1] = 0;
 158   3                                      uchSendBuf[2] = 3;
 159   3                                      uchSendBuf[3] = 0xD;
 160   3                                      uchSendBuf[4] = pOutput->iDataSpan / 256;
 161   3                                      uchSendBuf[5] = pOutput->iDataSpan % 256;                                                 
 162   3                                      SendPackage(3,1,uchSendBuf);
 163   3                                      break;
 164   3      
 165   3                              case SET_MODULE_STATUS:                                          //0xa5                                                                         
 166   3                                      SetModuleStatusMain(*(unsigned char *)&pInput[4]);//设置状态到主模块              
 167   3                                      ClearSelfFlag();        
 168   3                                      break;
 169   3      
 170   3                              case CONFIG_CHANNEL_PARA:               //0x55                  
 171   3                                      if (((uchCPUAddressStatus == 0) && (pInput[4] == 1 || pInput[4] == 2)) 
 172   3                                                      || ((uchCPUAddressStatus == 1) && (pInput[4] == 3 || pInput[4] == 4)))
 173   3                                      {
 174   4                                              if (uchModuleConfigStatus == 0x01)               //只有在Config状态下才能配置通道参数
 175   4                                              {                               
 176   5                                                      uiOffset = *((unsigned int *)&pInput[5]);
 177   5                                                      uiLength = *((unsigned int *)&pInput[7]);
 178   5                                                      uiLength = uiLength*2;                                                                                          
C51 COMPILER V7.10   COMM                                                                  09/18/2008 14:09:30 PAGE 4   

 179   5                                                      uiOffset = AddrMap(uiOffset);
 180   5      
 181   5                                                      uiForeChannelType = *((unsigned int *)&pInput[59]);        //20080529
 182   5                                                      JudgeChannelTypePara();                                                                    //20080529
 183   5                                                      *((unsigned int *)&pInput[59]) = uiForeChannelType;        //20080529
 184   5      
 185   5      
 186   5                                                      if ((pInput[4] == 1) || (pInput[4] == 2))
 187   5                                                      {
 188   6                                                              p = (unsigned char  xdata *)&pOutput->Ch[pInput[4] - 1] + uiOffset*2;
 189   6                                                      }
 190   5                                                      else if ((pInput[4] == 3) || (pInput[4] == 4))
 191   5                                                      {
 192   6                                                              p = (unsigned char  xdata *)&pOutput->Ch[pInput[4] - 3] + uiOffset*2;   
 193   6                                                      }
 194   5                                                      memcpy(p,(unsigned char*)&pInput[9],uiLength);                                                                                          
 195   5                                                      WriteSystemPara(0,(unsigned char xdata *)pOutput, PARALENGTH*2);           // flash module
 196   5                                                      SetModuleChannelParaStatusMain(1);         //通知框架参数有变化,需要判断处理及初始化变量
 197   5                                                      SetModuleNewConfigStatusMain(1);         //将模块被重新配置过的状态标志位送到框架中
 198   5                                                      InitFramemoduleParameters();             //最新添加
 199   5                                                      InitAlarmModuleSoftPara();                      //配置参数重新初始化报警参数
 200   5                                                      SetAfreshConfigFlagAlarm(pInput[4],1);
 201   5                                              }       //需要重新初始化AD
 202   4                                      }
 203   3                                      break;
 204   3      
 205   3                              case CONFIG_FACTORY_INFO:                                         //0x57
 206   3                                      if (uchModuleConfigStatus == 0x01)              //Config状态才能进行厂家信息配置
 207   3                                      {
 208   4                                              uiOffset = *((unsigned int *)&pInput[4]);
 209   4                                              uiLength = *((unsigned int *)&pInput[6]);
 210   4                                              if (*((unsigned int *)&pInput[16]) != MODULE20)

⌨️ 快捷键说明

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