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

📄 contact.lst

📁 51单片机C语言常用模块与综合系统设计实例精讲
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   CONTACT                                                               10/13/2006 09:21:08 PAGE 1   


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

stmt level    source

   1          #include <./Atmel/at89x52.h>
   2          #include <stdio.h>
   3          #include <absacc.h>
   4          #include <string.h>
   5          #include "source.h"
   6          /**为下载协议,与第14章的下载协议是一样的**/
   7          #define FSUCCESS 0
   8          #define FERROR   1  
   9          #define FDOVER  2
  10          void print_sbuf(unsigned char c){
  11   1              dst_buf[dst_head]=c; 
  12   1              dst_head ++;
  13   1              dst_head %=DST_LEN; 
  14   1      }
  15          #define REPLAY_LEN 9
  16          void reply_dwn(unsigned char flag,unsigned char *rbuf){//rbuf is the buf that downlaod data.
  17   1              unsigned char reply[REPLAY_LEN];
  18   1              struct  yushi rply_crc;
  19   1              unsigned char i;
  20   1              reply[0]=FDWN_FHD;
  21   1              reply[1]=flag;
  22   1              reply[2]=rbuf[2];
  23   1              reply[3]=rbuf[3];
  24   1              reply[4]=rbuf[4];
  25   1              reply[5]=0x00;
  26   1              reply[6]=0x00;
  27   1              init_crccheck(&rply_crc);
  28   1              for(i=0;i<7;i++){
  29   2                      crccheck(reply[i],&rply_crc);
  30   2              }
  31   1              reply[7]=rply_crc.h;
  32   1              reply[8]=rply_crc.l;
  33   1              for(i=0;i<REPLAY_LEN;i++){      
  34   2                      print_sbuf(*(reply+i));
  35   2              }
  36   1              TI=1;
  37   1      }
  38          void flash_download(void){
  39   1              union SFADD   dwn_adres;
  40   1              unsigned char fdata[FDWN_LEN];
  41   1              unsigned char fsm_fdl;
  42   1              unsigned char cnt;
  43   1              unsigned char erase_sec=0;
  44   1              unsigned int  sector_section=0;
  45   1              struct yushi fcrc;
  46   1              fsm_fdl=0;
  47   1              while(1){
  48   2                      if(dsr_tail!=dsr_head){         
  49   3                              if(fsm_fdl==0){//search frame head
  50   4                                      if(dsr_buf[dsr_tail]==FDWN_FHD){
  51   5                                              fsm_fdl=1;//head had found.
  52   5                                              fdata[0]=FDWN_FHD;
  53   5                                              cnt=1;
  54   5                                      }
  55   4                              }
C51 COMPILER V7.06   CONTACT                                                               10/13/2006 09:21:08 PAGE 2   

  56   3                              else if(fsm_fdl==1){//receive type byte
  57   4                                      if(cnt<FDWN_LEN-1){
  58   5                                                      fdata[cnt]=dsr_buf[dsr_tail];
  59   5                                                      cnt++;
  60   5                                      }
  61   4                                      else{//finish receive data.
  62   5                                              fdata[cnt]=dsr_buf[dsr_tail];
  63   5                                              if(1){//mult_crccheck(fdata,FDWN_LEN,struct &fcrc)==0){//crc ok
  64   6                                                      dwn_adres.c[1]=fdata[2];
  65   6                                                      dwn_adres.c[2]=fdata[3];
  66   6                                                      dwn_adres.c[3]=fdata[4];
  67   6                                                      sector_section=dwn_adres.c[1];//convert to sector.
  68   6                                                      sector_section <<=8;
  69   6                                                      sector_section &=0xff00;
  70   6                                                      sector_section |=dwn_adres.c[2];
  71   6                                                      sector_section >>=5;
  72   6                                                      if(((dwn_adres.c[2]&0x1f)==0x00)&&(dwn_adres.c[3]==0x00)){//A0~A11 IS 0 it indicaate across the sect
             -or
  73   7                                                      if(sector_section<8){//is sector SA0~SA7
  74   8                                                                      erase_sec=(unsigned char)sector_section;
  75   8                                                                      delay_10us(15);
  76   8                                                                      if(erase_sector(erase_sec)){//erase sector ok.
  77   9                                                                      }
  78   8                                                                      else{
  79   9                                                                              reply_dwn(erase_sec,fdata);
  80   9                                                                      }
  81   8                                                              }
  82   7                                                              else if((sector_section&0x7)==0){//sector is biger than 8.
  83   8                                                                      sector_section >>=3;
  84   8                                                                      erase_sec=(unsigned char)(sector_section&0xff);
  85   8                                                                      erase_sec +=7;
  86   8                                                                      delay_10us(15);
  87   8                                                                      if(erase_sector(erase_sec)){//erase sector ok.
  88   9                                                                      }
  89   8                                                                      else{
  90   9                                                                              reply_dwn(erase_sec,fdata);
  91   9                                                                      }
  92   8                                                              }
  93   7                                                      }
  94   6                                                      for(cnt=0;cnt<128;cnt++){
  95   7                                                              write_flash(&dwn_adres,fdata[5+cnt]);
  96   7                                                              dwn_adres.l ++;
  97   7                                                      }
  98   6                                                      if(fdata[1]==0x00){//download data
  99   7                                                              reply_dwn(FSUCCESS,fdata);
 100   7                                                      }
 101   6                                                      else if(fdata[1]==0x01){//download finsish.
 102   7                                                              reply_dwn(FDOVER,fdata);//for mutil file download ,power down again to into normal mode.
 103   7                                                      }
 104   6                                              }
 105   5                                              else{//CRC error
 106   6                                                      reply_dwn(FERROR,fdata);
 107   6                                              }
 108   5                                              fsm_fdl=0;//search frame head again.                                    
 109   5                                      }
 110   4                              }       
 111   3                              dsr_tail++;
 112   3                              dsr_tail %=DSR_LEN;
 113   3                      }
 114   2                      else{
 115   3                              //wait receive serial data.
 116   3                      }
C51 COMPILER V7.06   CONTACT                                                               10/13/2006 09:21:08 PAGE 3   

 117   2              }
 118   1      }
*** WARNING C280 IN LINE 45 OF CONTACT.C: 'fcrc': unreferenced local variable
 119          /**为信息传输协议***/

⌨️ 快捷键说明

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