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

📄 ds1302.lst

📁 内部HFGHGFHGFHGFHGFHGFHGFHGFHG
💻 LST
字号:
C51 COMPILER V7.50   DS1302                                                                05/11/2009 22:41:48 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE DS1302
OBJECT MODULE PLACED IN DS1302.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE DS1302.C BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include "config.h"
   2          
   3          sbit   RST  = P0^3;
   4          sbit   IO   = P0^4;
   5          sbit   CLOCK=P0^5;
   6          
   7          uint8   ReadTimeCnt;
   8          uint8   sec,min,hour,day,month,year;
   9          
  10          
  11          
  12          void    reset_3w(void);
  13          void    wbyte_3w(uint8 W_Byte);
  14          uint8   rbyte_3w(void);
  15          
  16          void    WriteByte(uint8 add, uint8 sdata);
  17          uint8   ReadByte(uint8 addr);
  18          void    ReadTime(void);
  19          void    Ds1302Init(void);
  20          
  21          void    reset_3w(void)  /* ----- reset and enable the 3-wire interface ------ */
  22          {
  23   1              CLOCK = 0;
  24   1          RST   = 0;
  25   1              RST   = 1;
  26   1      }
  27          
  28          
  29          void    wbyte_3w(uint8 W_Byte)  /* ------ write one byte to the device ------- */
  30          {
  31   1          uint8 i;
  32   1              for(i = 0; i < 8; i++)
  33   1          {
  34   2                  IO = 0;
  35   2                  if(W_Byte & 0x01)
  36   2                      {
  37   3                              IO = 1; /* set port pin high to read data */
  38   3                      }
  39   2                  CLOCK = 0;
  40   2              CLOCK = 1;
  41   2                  W_Byte >>= 1;
  42   2          }
  43   1      }
  44          uint8   rbyte_3w(void)  /* ------- read one byte from the device -------- */
  45          {
  46   1          uint8  i;
  47   1          uint8  R_Byte;
  48   1          uint8  TmpByte;
  49   1              R_Byte = 0x00;
  50   1              IO = 1;
  51   1              for(i = 0; i < 8; i++)
  52   1          {
  53   2                  CLOCK = 1;
  54   2                  CLOCK = 0;
  55   2                  TmpByte = (uint8)IO;
C51 COMPILER V7.50   DS1302                                                                05/11/2009 22:41:48 PAGE 2   

  56   2                  TmpByte <<= 7;
  57   2                  R_Byte >>= 1;
  58   2                  R_Byte |= TmpByte;
  59   2          }
  60   1              return R_Byte;
  61   1      }
  62          
  63          
  64          
  65          
  66          
  67          
  68          void WriteByte(uint8 add, uint8 sdata)
  69          {
  70   1              reset_3w();
  71   1              wbyte_3w(add);
  72   1              wbyte_3w(sdata);
  73   1              reset_3w();
  74   1      }
  75          
  76          uint8 ReadByte(uint8 addr)
  77          {   
  78   1          uint8 readtemp;
  79   1              reset_3w();
  80   1              wbyte_3w(addr);
  81   1              readtemp = rbyte_3w();
  82   1              reset_3w();
  83   1              return readtemp;
  84   1      }
  85          
  86          
  87          void    Ds1302Init(void)
  88          {
  89   1              WriteByte(0x8e,0x00);          //写使能
  90   1          sec   = ReadByte(DS1302SEC_R) & 0x7f;      // clk_sec
  91   1              min   = ReadByte(DS1302MIN_R) & 0x7f;      // clk_min 1 0 0 0 0 0 1 1
  92   1              hour  = ReadByte(DS1302HOUR_R) & 0x3f;      // clk_hour
  93   1      
  94   1              day   = ReadByte(DS1302DAY_R) & 0x3f;      // clk_day
  95   1          if(day==0)
  96   1          {
  97   2              day=1;
  98   2          }
  99   1              month = ReadByte(DS1302MONTH_R);      // clk_month
 100   1          if(month==0)
 101   1          {
 102   2              month=1;
 103   2          }
 104   1              year  = ReadByte(DS1302YEAR_R);      // clk_year*/
 105   1      
 106   1      
 107   1          WriteByte(DS1302SEC_W,sec);            //秒,并且启动时钟
 108   1          WriteByte(DS1302MIN_W,min);            //分
 109   1          WriteByte(DS1302HOUR_W,hour);           //时
 110   1          WriteByte(DS1302DAY_W,day);            //日
 111   1          WriteByte(DS1302MONTH_W,month);          //月
 112   1          WriteByte(DS1302YEAR_W,year);           //年
 113   1      }
 114          
 115          
 116          
 117          
C51 COMPILER V7.50   DS1302                                                                05/11/2009 22:41:48 PAGE 3   

 118          void    ReadTime(void)
 119          {
 120   1          if( ReadTimeCnt > 20 )
 121   1          {
 122   2              ReadTimeCnt = 0;
 123   2              sec   = ReadByte(DS1302SEC_R)&0x7f;
 124   2              min   = ReadByte(DS1302MIN_R)&0x7f;
 125   2              hour  = ReadByte(DS1302HOUR_R)&0x3f;
 126   2              day   = ReadByte(DS1302DAY_R)&0x3f;
 127   2              month = ReadByte(DS1302MONTH_R)&0x1f;
 128   2              year  = ReadByte(DS1302YEAR_R)&0xff;
 129   2          }
 130   1      }
 131          
 132          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    241    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      7    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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