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

📄 timer.lst

📁 一个用C51编写的倒计时程序
💻 LST
字号:
C51 COMPILER V7.01  TIMER                                                                  05/26/2005 12:03:47 PAGE 1   


C51 COMPILER V7.01, COMPILATION OF MODULE TIMER
OBJECT MODULE PLACED IN timer.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE timer.c ROM(SMALL) BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          //------------------------------
   2          //设置当前值:FE A0 02 MM NN  (BCD码)
   3          //要当前值:  FE A1 01 00 回传值 FE A1 02 MM NN   BCD码)
   4          //------------------------------
   5          #include<At89x52.h>
   6          #include<initled.h>
   7          //------------------------------------------
   8          #define condition_1 time_min==0&&time_sec==0
   9          #define condition_2 time_min==0&&time_sec!=0
  10          #define condition_3 time_min!=0&&time_sec==0
  11          #define condition_4 time_min!=0&&time_sec!=0
  12          #define so_pclength    p_pc_head-so_pc_buf
  13          //------------------------------------------
  14          sbit d_clk=P3^7;                
  15          sbit d_dat=P3^6;                
  16          sbit d_st=P3^5;                 
  17          
  18          bit bit_timech=0;
  19          
  20          unsigned char d[5];
  21          unsigned char so_pc_buf[10];
  22          unsigned char time60,time_min=99,time_sec=59,*p_pc_head=so_pc_buf;
  23          //////////////////////
  24          void out_disp(unsigned char *p) 
  25          {unsigned char i,j;     
  26   1              for(i=0;i<5;i++,p++) 
  27   1             {for (j=0;j<8;j++) 
  28   2                 {if (*p&1) d_dat=1;else d_dat=0;
  29   3                             d_clk=1;*p>>=1;d_clk=0;
  30   3                         }
  31   2                 }
  32   1      d_st=1;
  33   1      for(i=0;i<10;i++);
  34   1      d_st=0;
  35   1      }
  36          //------------------------------------
  37          //d0min/ d1min% d2- d3sec/ d4sec%
  38          //------------------------------------
  39          void calculattime(void )
  40          {    if(condition_1);
  41   1      else if(condition_2)time_sec-=1;
  42   1      else if(condition_3){time_sec=59;time_min-=1;}
  43   1      else if(condition_4)time_sec-=1;
  44   1        else {time_sec=88;time_min=88;}
  45   1      
  46   1      d[0]=un_disp[time_min/10];d[1]=un_disp[time_min%10];
  47   1      d[2]=l_;
  48   1      d[3]=un_disp[time_sec/10];d[4]=un_disp[time_sec%10];
  49   1      out_disp(d);
  50   1      }
  51          ////////////////////
  52          void int_t0(void) interrupt 1 using 1
  53          {       TL0=0xa0;TH0=0x42;      
  54   1              if ((++time60)>=19) {time60=0;bit_timech=1;}    
  55   1      }
C51 COMPILER V7.01  TIMER                                                                  05/26/2005 12:03:47 PAGE 2   

  56          ////////////////////
  57          void int_pc(void) interrupt 4 using 2
  58          {        if(RI) {RI=0;
  59   2                   if((SBUF==0xfe)||(so_pclength>=8))p_pc_head=so_pc_buf;
  60   2                   *p_pc_head++=SBUF;
  61   2                  }
  62   1      }
  63          //------------------
  64          void pc_comand(void )
  65          {unsigned char datebuf;
  66   1      if((so_pclength)>=4)//while
  67   1             {if(so_pclength>=(so_pc_buf[2]+3))
  68   2                     {switch(so_pc_buf[1]){
  69   4                    case 0xa0:if(so_pc_buf[3]<=0x99&&so_pc_buf[4]<=0x99)
  70   4                                             {datebuf=so_pc_buf[3];
  71   5                                              time_min=(datebuf>>4)*10+(so_pc_buf[3]&=0x0f);
  72   5                                                              datebuf=so_pc_buf[4];
  73   5                                                      time_sec=(datebuf>>4)*10+(so_pc_buf[4]&=0x0f);}                                  
  74   4                                                      break;
  75   4                    case 0xa1:SBUF=0xfe;
  76   4                              while(TI==0);TI=0;SBUF=0xa1;
  77   4                                              while(TI==0);TI=0;SBUF=0x02;
  78   4                                                      while(TI==0);TI=0;SBUF=((datebuf=time_min/10)<<4)|(time_min%10);
  79   4                                                      while(TI==0);TI=0;SBUF=((datebuf=time_sec/10)<<4)|(time_sec%10);
  80   4                                                      while(TI==0);TI=0;
  81   4                                                      break;
  82   4                      default:break;}
  83   3                  p_pc_head=so_pc_buf;
  84   3                    }
  85   2             }
  86   1      //return(0);
  87   1      }
  88          ////////////////////
  89          void watchdog(void )
  90          {unsigned char i;
  91   1      d_clk=1;
  92   1      for(i=0;i<10;i++);
  93   1      d_clk=0;
  94   1      }
  95          ////////////////////
  96          void main(void) 
  97          {       TMOD=0x21;
  98   1              SCON=0x50;
  99   1          TH1=TL1=0xE8; //1200
 100   1          TH0=0x42;// ;50MS
 101   1              TL0=0xA0;
 102   1          TR1=TR0=ET0=ES=1;
 103   1          ET1=0;
 104   1              EA=1;
 105   1          d_clk=d_dat=d_st=0;
 106   1               
 107   1              while (1) 
 108   1              {if(bit_timech){bit_timech=0;calculattime();}
 109   2              watchdog();
 110   2          pc_comand();
 111   2              }
 112   1      }
 113          //////////////////////


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    559    ----
C51 COMPILER V7.01  TIMER                                                                  05/26/2005 12:03:47 PAGE 3   

   CONSTANT SIZE    =     11    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     21       4
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      1    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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