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

📄 download.lst

📁 对W29c040读写程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.10   DOWNLOAD                                                              03/30/2007 17:02:48 PAGE 1   


C51 COMPILER V7.10, COMPILATION OF MODULE DOWNLOAD
OBJECT MODULE PLACED IN download.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE download.c LARGE BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <reg52.h>
   2          //#include "upsd3300.h"
   3          //#include "PSD_Register.h"
   4          
   5          #include "ext_var.h"
   6          #include "SerialPort.h"
   7          #include "w29c040drv.h"
   8          #include "download.h"
   9          
  10          #include <stdio.h>
  11          #include <string.h>
  12          
  13          
  14          //串口接收结构
  15          typedef struct
  16          {
  17                  uchar Finish;                           //设定未接收完毕
  18                  uint  Len;                                      //已接收长度
  19                  uint  CmdLen;                           //命令总长度
  20                  uchar Buffer[128+1];            //接收缓冲区
  21                  uchar Data[PAGE_SIZE+1];        //页数据
  22                  int   DataLen;                          //页数据长度
  23          }RS232_REC;
  24          
  25          //文件信息结构
  26          typedef struct
  27          {
  28                  uint  Pages;            //总共要写页数
  29                  uint  Addr;                     //写入起始地址
  30          }FILE;
  31          
  32          
  33          static RS232_REC Rec;   //串口接收
  34          static FILE File;       //文件信息
  35          
  36          /**********************************************************************
  37          * 函 数 名: InitRec
  38          * 功能描述: 初始化接收相关变量
  39          * 函数说明: 
  40          * 调用函数: 
  41          * 全局变量:     
  42          * 输    入: 无
  43          * 返    回: 无
  44          * 设 计 者: wangyong                         日期:2007-03-24
  45          * 修 改 者: wangyong                         日期:2007-03-30
  46          * 版    本: WTFISCAL04 KEYBOARDV1.0D100
  47          **********************************************************************/
  48          void InitRec( void )
  49          {
  50   1              Rec.Finish=FALSE; //设定未接收完毕
  51   1              Rec.Len=0;      //已接收长度
  52   1              Rec.CmdLen=0; //PC发给下位机的命令的总长度
  53   1              Rec.DataLen=0;  //页数据长度
  54   1      }
  55          
C51 COMPILER V7.10   DOWNLOAD                                                              03/30/2007 17:02:48 PAGE 2   

  56          /**********************************************************************
  57          * 函 数 名: SendCmdStr
  58          * 功能描述: 向PC发送命令字串
  59          * 函数说明: 
  60          * 调用函数: 
  61          * 全局变量:     
  62          * 输    入: Cmd--命令字串
  63                                  Len--命令字串长度
  64          * 返    回: 无
  65          * 设 计 者: wangyong                         日期:2007-03-25
  66          * 修 改 者: wangyong                         日期:2007-03-30
  67          * 版    本: WTFISCAL04 KEYBOARDV1.0D100
  68          **********************************************************************/
  69          void SendCmdStr(uchar *Cmd,uint Len)
  70          {
  71   1              
  72   1              uchar CS;
  73   1              uchar cmdstr[20];
  74   1              uint  i;
  75   1              uint  cmdlen;
  76   1      
  77   1      
  78   1              //命令头
  79   1              cmdstr[0]=0x55;
  80   1              cmdstr[1]=0xAA;
  81   1      
  82   1              //LH + LL + /LH + /LL + CMD + DATA + CS相加的长度(除命令头外)
  83   1              cmdlen=5+Len;
  84   1      
  85   1              //长度
  86   1              cmdstr[2]=cmdlen/256;
  87   1              cmdstr[3]=cmdlen%256;
  88   1      
  89   1              //长度取反
  90   1              cmdstr[4]=~cmdstr[2];
  91   1              cmdstr[5]=~cmdstr[3];
  92   1      
  93   1              //保存命令字
  94   1              //cmdstr[6]=Cmd;
  95   1              memcpy(cmdstr+6,Cmd,Len);
  96   1      
  97   1              //计算出抑或校验和CS
  98   1              //cmdlen+1为完整命令长度减去CS长度(1字节)
  99   1              CS=cmdstr[0];
 100   1              for(i=1;i<cmdlen+1;i++)
 101   1              {
 102   2                      CS=CS^cmdstr[i];
 103   2              }
 104   1              cmdstr[6+Len]=CS;
 105   1      
 106   1              //串口发送命令
 107   1              //cmdlen+2为完整命令长度
 108   1              for(i=0;i<cmdlen+2;i++)
 109   1              {
 110   2                      SerialPort_send(cmdstr[i]);
 111   2              }
 112   1      }
 113          
 114          /**********************************************************************
 115          * 函 数 名: VerifyCmdStr
 116          * 功能描述: 验证命令串合法性并解析出命令字,数据,数据长度
 117          * 函数说明: 
C51 COMPILER V7.10   DOWNLOAD                                                              03/30/2007 17:02:48 PAGE 3   

 118          * 调用函数: 无
 119          * 全局变量:
 120          * 输    入: *Cmd--命令字
 121                                  *DataLen--数据长度
 122          * 返    回: TRUE--通过合法性
 123                                  FALSE--未通过合法性
 124          * 设 计 者: wangyong                         日期:2007-03-25
 125          * 修 改 者: wangyong                         日期:2007-03-25
 126          * 版    本: 
 127          **********************************************************************/
 128          bool VerifyCmdStr(uchar *Cmd,uint *DataLen)
 129          {
 130   1              uchar CS;
 131   1              uint  i;
 132   1              
 133   1              //命令头错误
 134   1              if(Rec.Buffer[0]!=0x55 || Rec.Buffer[1]!=0xaa) return FALSE;
 135   1      
 136   1              //判断cs是否正确
 137   1              CS=Rec.Buffer[0];
 138   1      
 139   1              //计算异或和
 140   1              for(i=1;i<Rec.Len-1;i++)
 141   1              {
 142   2                      CS=CS^Rec.Buffer[i];
 143   2              }
 144   1      
 145   1              //校验位出错
 146   1              if(CS!=Rec.Buffer[Rec.Len-1]) return FALSE;
 147   1      
 148   1              //得到命令字
 149   1              *Cmd=Rec.Buffer[6];
 150   1      
 151   1              //数据长度
 152   1              *DataLen=(Rec.Buffer[2]*256+Rec.Buffer[3])-5;
 153   1      
 154   1              return TRUE;
 155   1      }
 156          
 157          /**********************************************************************
 158          * 函 数 名: Download
 159          * 功能描述: 下载处理
 160          * 函数说明: 
 161          * 调用函数: 无
 162          * 全局变量:
 163          * 输    入: 无
 164          * 返    回: 无
 165          * 设 计 者: wangyong                         日期:2007-03-24
 166          * 修 改 者: wangyong                         日期:2007-03-24
 167          * 版    本: 
 168          **********************************************************************/
 169          void Download( void )
 170          {
 171   1              uchar Cmd; //命令字
 172   1              uint  DataLen;  //数据长度
 173   1              uint  TempLen;
 174   1              bool  CommOk; //命令通讯状态
 175   1              //uint i;
 176   1      
 177   1              //串口初始化
 178   1              SerialPort_init();
 179   1      
C51 COMPILER V7.10   DOWNLOAD                                                              03/30/2007 17:02:48 PAGE 4   

 180   1      restart:
 181   1      

⌨️ 快捷键说明

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