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

📄 function.lst

📁 51单片机C语言常用模块与综合系统设计实例精讲
💻 LST
字号:
C51 COMPILER V7.06   FUNCTION                                                              10/29/2006 14:35:12 PAGE 1   


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

stmt level    source

   1          #include <./Atmel/at89x52.h>
   2          #include <stdio.h>
   3          #include <absacc.h>
   4          #include <intrins.h>
   5          #include <string.h>
   6          #include "source.h"
   7          #define FSUCCESS 0
   8          #define FERROR   1  
   9          #define FDOVER   2
  10          bit TDBdata_over;
  11          unsigned char dst_buf[DST_LEN];/*为数据传输口的发送缓冲区.*/
  12          unsigned char dst_head;        /*为目前要发送数据存储的位置*/
  13          unsigned char dst_tail;        /*为真正发送数据存储的位置,当head和tail相等时表明发送数据缓冲区无数据*/
  14          unsigned char dsr_buf[DSR_LEN];/*接收数据缓冲区*/
  15          unsigned char dsr_head;        /*从串口接收到的数据存储的位置*/
  16          unsigned char dsr_tail;        /*从串口接收缓冲区读取数据的位置,当tail和head相等时间标兵接收缓冲区无数据*
             -/
  17          void delay_macnine_ncircle(unsigned char cnt){//11+6*cnt machin circle.
  18   1              while(cnt--);
  19   1      }
  20          void delay_10us(unsigned char tus){/*在C51时钟的频率为18.432MHZ时,延时10微秒*/
  21   1              tus--;
  22   1              while(tus--){
  23   2                      _nop_();_nop_();_nop_();
  24   2                      _nop_();_nop_();_nop_();
  25   2                      _nop_();_nop_();_nop_();
  26   2              }
  27   1      }
  28          void print_sbuf(unsigned char c){/*向串口发送缓冲区中写数据*/
  29   1              dst_buf[dst_head]=c; 
  30   1              dst_head ++;
  31   1              dst_head %=DST_LEN; 
  32   1      }
  33          #define REPLAY_LEN 9
  34          void reply_dwn(unsigned char flag,unsigned char *rbuf){/*rbuf 是下载的数据的指针,此函数是对下载的数据进行
             -应答*/
  35   1              unsigned char reply[REPLAY_LEN];
  36   1              struct  yushi rply_crc;
  37   1              unsigned char i;
  38   1              reply[0]=FDWN_FHD;
  39   1              reply[1]=flag;
  40   1              reply[2]=rbuf[2];
  41   1              reply[3]=rbuf[3];
  42   1              reply[4]=rbuf[4];
  43   1              reply[5]=0x00;
  44   1              reply[6]=0x00;
  45   1              init_crccheck(&rply_crc);
  46   1              for(i=0;i<7;i++){
  47   2                      crccheck(reply[i],&rply_crc);
  48   2              }
  49   1              reply[7]=rply_crc.h;
  50   1              reply[8]=rply_crc.l;
  51   1              for(i=0;i<REPLAY_LEN;i++){      
  52   2                      print_sbuf(*(reply+i));
  53   2              }
C51 COMPILER V7.06   FUNCTION                                                              10/29/2006 14:35:12 PAGE 2   

  54   1              TI=1;
  55   1      }
  56          #define ERASE_SECTOR 
  57          void flash_download(void){/*数据下载,等在数据下载完毕后此函数才退出*/
  58   1              union SFADD   dwn_adres;
  59   1              unsigned char fdata[FDWN_LEN];
  60   1              unsigned char fsm_fdl;
  61   1              unsigned char cnt;
  62   1              unsigned char erase_sec=0;
  63   1              unsigned int  sector_section=0;
  64   1              unsigned char temp;
  65   1              struct yushi fcrc;
  66   1              fsm_fdl=0;
  67   1              while(1){/*进入死循环,只有计算机把所有的数据下载完毕才推出*/
  68   2                      if(dsr_tail!=dsr_head){/*串口接收缓冲区中有数据*/       
  69   3                              if(fsm_fdl==0){/*串口接收在寻找帧头(0X7E)的状态*/
  70   4                                      if(dsr_buf[dsr_tail]==FDWN_FHD){/*串口接收的数据是帧头*/
  71   5                                              fsm_fdl=1;/*把串口接收的状态设置为接收数据*/
  72   5                                              fdata[0]=FDWN_FHD;/*把接收到的字节存储在接收的数据中*/
  73   5                                              cnt=1;
  74   5                                      }
  75   4                              }
  76   3                              else if(fsm_fdl==1){/*串口的状态在接受数据状态*/
  77   4                                      if(cnt<FDWN_LEN-1){/*135个字节的帧还没有接收完毕*/
  78   5                                                      fdata[cnt]=dsr_buf[dsr_tail];
  79   5                                                      cnt++;
  80   5                                      }
  81   4                                      else{/*一帧数据接收完毕*/
  82   5                                              fdata[cnt]=dsr_buf[dsr_tail];
  83   5                                              if(1){//mult_crccheck(fdata,FDWN_LEN,struct &fcrc)==0){/*由于串口出错的概率比较小,没有进行CRC效验*/
  84   6                                                      dwn_adres.c[1]=fdata[2];/*提取出要写到flash的地址字节*/
  85   6                                                      dwn_adres.c[2]=fdata[3];
  86   6                                                      dwn_adres.c[3]=fdata[4];
  87   6      #ifdef ERASE_SECTOR
  88   6                                                      sector_section=dwn_adres.c[1];/*把地址字节转化为扇区地址*/
  89   6                                                      sector_section <<=8;
  90   6                                                      sector_section &=0xff00;
  91   6                                                      sector_section |=dwn_adres.c[2];
  92   6                                                      sector_section >>=5;
  93   6                                                      if(((dwn_adres.c[2]&0x1f)==0x00)&&(dwn_adres.c[3]==0x00)){/*如果A0~A11为0,那么就表明要写的数据跨越

⌨️ 快捷键说明

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