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

📄 ds1302.lst

📁 一个数字显示时钟的程序
💻 LST
字号:
C51 COMPILER V7.50   DS1302                                                                06/12/2008 09:13:37 PAGE 1   


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

line level    source

   1          #include "regx52.h"
   2          #include "lcd1602.h"
   3          
   4          #define DS_RST P2_5
   5          #define DS_IO P2_7
   6          #define DS_CLK P2_6
   7          
   8          unsigned char Time[7]={0x56,0x00,0x00,0x01,0x01,0x05,0x08};
   9          unsigned char Temp_Buffer[2];
  10          
  11          void DS_Open(void)
  12          {
  13   1              DS_CLK=0;
  14   1              DS_RST=1;
  15   1      }
  16          
  17          void DS_Close(void)
  18          {
  19   1              DS_RST=0;
  20   1              DS_CLK=0;
  21   1      }
  22          
  23          void DS_Write_Byte(unsigned char dat)
  24          {
  25   1              unsigned char i;
  26   1              for(i=0;i<8;i++)
  27   1              {
  28   2                      if(dat&0x01)
  29   2                      {
  30   3                              DS_IO=1;
  31   3                      }
  32   2                      else
  33   2                      {
  34   3                              DS_IO=0;
  35   3                      }
  36   2                      DS_CLK=1;
  37   2                      _nop_();
  38   2                      _nop_();
  39   2                      DS_CLK=0;
  40   2                      dat>>=1;
  41   2              }
  42   1              DS_IO=1;
  43   1      }
  44          
  45          unsigned char DS_Read_Byte(void)
  46          {
  47   1              unsigned char i,r_dat;
  48   1              for(i=0;i<8;i++)
  49   1              {
  50   2                      r_dat>>=1;
  51   2                      if(DS_IO)
  52   2                      {
  53   3                              r_dat+=0x80;
  54   3                      }
  55   2                      DS_CLK=1;
C51 COMPILER V7.50   DS1302                                                                06/12/2008 09:13:37 PAGE 2   

  56   2                      _nop_();
  57   2                      _nop_();
  58   2                      DS_CLK=0;
  59   2              }
  60   1              return r_dat;
  61   1      }
  62          
  63          void DS_Get_Time(unsigned char *p)
  64          {
  65   1              unsigned char i;
  66   1              DS_Open();
  67   1              DS_Write_Byte(0xbf);
  68   1              DS_Close();
  69   1              DS_Open();
  70   1              DS_Write_Byte(0xbf);
  71   1              for(i=0;i<7;i++)
  72   1              {
  73   2                      p[i]=DS_Read_Byte();
  74   2              }
  75   1              DS_Close();
  76   1      }
  77          
  78          void DS_Set_Time(unsigned char *p)
  79          {
  80   1              unsigned char i;
  81   1              p[0]&=0x7f;
  82   1              DS_Open();
  83   1              DS_Write_Byte(0xbe);
  84   1              for(i=0;i<7;i++)
  85   1              {
  86   2                      DS_Write_Byte(p[i]);
  87   2              }
  88   1              DS_Write_Byte(0x00);
  89   1              DS_Close();
  90   1      }
  91          
  92          void DS_Initial(void)
  93          {
  94   1              unsigned char dat;
  95   1              DS_RST=0;
  96   1              DS_Open();
  97   1              DS_Write_Byte(0x8e);
  98   1              DS_Write_Byte(0x00);
  99   1              DS_Close();
 100   1              
 101   1              DS_Open();
 102   1              DS_Write_Byte(0x81);
 103   1              dat=DS_Read_Byte();
 104   1              DS_Close();
 105   1      
 106   1              dat&=0x7f;
 107   1      
 108   1              DS_Open();
 109   1              DS_Write_Byte(0x80);
 110   1              DS_Write_Byte(dat);
 111   1              DS_Close();
 112   1      
 113   1              DS_Open();
 114   1              DS_Write_Byte(0x90);
 115   1              DS_Write_Byte(0xa5);
 116   1              DS_Close();
 117   1      
C51 COMPILER V7.50   DS1302                                                                06/12/2008 09:13:37 PAGE 3   

 118   1              DS_Open();
 119   1              DS_Write_Byte(0x8e);
 120   1              DS_Write_Byte(0x80);
 121   1              DS_Close();
 122   1      }
 123          
 124          void Change_To_Char(unsigned int t,unsigned char *str)
 125          {
 126   1              unsigned char a[2]; 
 127   1              char i, j;                                                      
 128   1              a[0]=(t/10)%10;                                                 
 129   1              a[1]=t%10;                                                                                                            
             -                                                                           
 130   1              for(i=0; i<2; i++)                              
 131   1                      a[i]=a[i]+'0';                                          
 132   1              for(i=0; (a[i]=='0')&&(i<2); i++)                     
 133   1                      {
 134   2                              ;
 135   2                      }                       
 136   1              for(j=0; j<i; j++)                              
 137   1                      {       
 138   2                              *str='0';  
 139   2                              str++; 
 140   2                      }                               
 141   1              for(; i<2; i++)                                         
 142   1                      { 
 143   2                              *str=a[i]; 
 144   2                              str++; 
 145   2                      }     
 146   1                      
 147   1              *str='\0'; 
 148   1      }
 149          
 150          void Delay(void)
 151          {
 152   1              unsigned char i,j;
 153   1              for(i=0;i<224;i++)
 154   1                      for(j=0;j<224;j++)
 155   1                              ;
 156   1      }
 157          
 158          void main(void)
 159          {       
 160   1              unsigned char ii;
 161   1              unsigned char year;
 162   1              Lcd_Initial();
 163   1              DS_Initial();
 164   1              Gotoxy(0,0);
 165   1              Print("    /  /        ");
 166   1              Gotoxy(0,1);
 167   1              Print("  :             ");
 168   1              DS_Set_Time(&Time[0]);
 169   1              while(1)
 170   1              {
 171   2                      year=20;
 172   2                      DS_Get_Time(&Time[0]);
 173   2                      ii=Time[1]&0x0f;
 174   2                      Time[1]>>=4;
 175   2                      Time[1]&=0x07;
 176   2                      Time[1]=Time[1]*10+ii;                  
 177   2                      Change_To_Char(Time[1],&Temp_Buffer[0]);
 178   2                      Gotoxy(3,1);
C51 COMPILER V7.50   DS1302                                                                06/12/2008 09:13:37 PAGE 4   

 179   2                      Print(&Temp_Buffer[0]);
 180   2                      
 181   2                      if(Time[2]&&0x80)
 182   2                      {
 183   3                              if(Time[2]&&0x20)
 184   3                              {
 185   4                                      Gotoxy(5,1);
 186   4                                      Print("(AM)");
 187   4                              }
 188   3                              else
 189   3                              {
 190   4                                      Gotoxy(5,1);
 191   4                                      Print("(PM)");
 192   4                              }
 193   3                      }
 194   2                      else
 195   2                      {
 196   3                              Gotoxy(5,1);
 197   3                              Print("(24th)");
 198   3                              ii=Time[2]&0x0f;
 199   3                              Time[2]>>=4;
 200   3                              Time[2]&=0x03;
 201   3                              Time[2]=Time[2]*10+ii;
 202   3                              Change_To_Char(Time[2],&Temp_Buffer[0]);
 203   3                              Gotoxy(0,1);
 204   3                              Print(&Temp_Buffer[0]);
 205   3                      }
 206   2      
 207   2                      ii=Time[3]&0x0f;
 208   2                      Time[3]>>=4;
 209   2                      Time[3]&=0x03;
 210   2                      Time[3]=Time[3]*10+ii;
 211   2                      Change_To_Char(Time[3],&Temp_Buffer[0]);
 212   2                      Gotoxy(8,0);
 213   2                      Print(&Temp_Buffer[0]);
 214   2      
 215   2                      ii=Time[4]&0x0f;
 216   2                      Time[4]>>=4;
 217   2                      Time[4]&=0x01;
 218   2                      Time[4]=Time[4]*10+ii;
 219   2                      Change_To_Char(Time[4],&Temp_Buffer[0]);
 220   2                      Gotoxy(5,0);
 221   2                      Print(&Temp_Buffer[0]);
 222   2                      
 223   2                      ii=Time[6]&0x0f;
 224   2                      Time[6]>>=4;
 225   2                      Time[6]&=0x0f;
 226   2                      Time[6]=Time[6]*10+ii;
 227   2                      Change_To_Char(Time[6],&Temp_Buffer[0]);
 228   2                      Gotoxy(2,0);
 229   2                      Print(&Temp_Buffer[0]);
 230   2                      Change_To_Char(year,&Temp_Buffer[0]);
 231   2                      Gotoxy(0,0);
 232   2                      Print(&Temp_Buffer[0]);
 233   2      
 234   2                      ii=Time[5]&0x07;
 235   2                      Gotoxy(12,1);
 236   2                      switch(ii)
 237   2                      {
 238   3                              case 0x01: Print("Mon"); break;
 239   3                              case 0x02: Print("Tue"); break;
 240   3                              case 0x03: Print("Wen"); break;
C51 COMPILER V7.50   DS1302                                                                06/12/2008 09:13:37 PAGE 5   

 241   3                              case 0x04: Print("Tue"); break;
 242   3                              case 0x05: Print("Fir"); break;
 243   3                              case 0x06: Print("Sat"); break;
 244   3                              case 0x07: Print("Sun"); break;
 245   3                              default: break;
 246   3                      }
 247   2                      Delay();
 248   2              }
 249   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1012    ----
   CONSTANT SIZE    =     75    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      9      16
   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 + -