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

📄 time.lst

📁 测温db18b20 液晶1602 显示时间和温度
💻 LST
字号:
C51 COMPILER V8.08   TIME                                                                  10/05/2008 18:43:22 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE TIME
OBJECT MODULE PLACED IN time.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE time.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include<reg52.h>
   2          #define uchar unsigned char
   3          #define uint unsigned int
   4          
   5          sbit lcden=P3^4;
   6          sbit lcdrs=P3^5;
   7          sbit dula=P2^6;
   8          sbit wela=P2^7;
   9          sbit rd=P3^1;
  10          sbit s1=P3^7;
  11          sbit s2=P3^6;
  12          sbit dq=P2^2;
  13          
  14          uchar code table1[]="2008-10-05"; uchar code table2[]="18:20:00";
  15           
  16          uchar i; uchar count=0; uchar miao,fen,shi;
  17          uchar wei;
  18          uchar tpl,tpm;
  19          uint wendu=0;
  20          
  21          void delay(uint x)
  22          {
  23   1              uint y,z;
  24   1              for(y=x;y>0;y--)
  25   1                      for(z=110;z>0;z--);
  26   1      }
  27          
  28          void write_date(uchar a)
  29          {
  30   1              lcden=0;
  31   1              lcdrs=1;
  32   1              P0=a;
  33   1              lcden=1;
  34   1              delay(2);
  35   1              lcden=0;
  36   1              delay(2);
  37   1      }
  38          void write_com(uchar a)
  39          {
  40   1              lcden=0;
  41   1              lcdrs=0;
  42   1              P0=a;
  43   1              lcden=1;
  44   1              delay(2);
  45   1              lcden=0;
  46   1              delay(2);
  47   1      }
  48          void init()
  49          {
  50   1              dula=0;
  51   1              wela=0;
  52   1              write_com(0x38);
  53   1              write_com(0x0c);
  54   1              write_com(0x06);
  55   1              write_com(0x01);
C51 COMPILER V8.08   TIME                                                                  10/05/2008 18:43:22 PAGE 2   

  56   1              write_com(0x80+1);
  57   1              for(i=0;i<10;i++)
  58   1              {
  59   2                      write_date(table1[i]);
  60   2                      delay(10);
  61   2              }  
  62   1              write_com(0x80+14);
  63   1              write_date(0xdf);write_date(0x43);
  64   1              write_com(0x80+0x40+4);
  65   1              for(i=0;i<8;i++)
  66   1              {
  67   2                      write_date(table2[i]);
  68   2                      delay(10);
  69   2              }
  70   1              TMOD=0x01;
  71   1              TH0=(65536-50000)/256;
  72   1              TL0=(65536-50000)%256;
  73   1              EA=1;
  74   1              ET0=1;
  75   1              TR0=1; 
  76   1      
  77   1      
  78   1      }
  79          
  80          void write_time(uchar address,uchar date)
  81          {
  82   1              uchar shi,ge;
  83   1              shi=date/10;
  84   1              ge=date%10;
  85   1              write_com(0x80+0x40+4+address);
  86   1              write_date(0x30+shi);
  87   1              write_date(0x30+ge);
  88   1      }
  89          void write_wendu(uchar address,uchar date)
  90          {
  91   1              uchar bai,shi,ge;
  92   1              bai=date/100;
  93   1              shi=date%100/10;
  94   1              ge=date%10;
  95   1              write_com(0x80+address);
  96   1              //write_date(0x30+bai);
  97   1              write_date(0x30+shi);
  98   1              write_date(0x30+ge);
  99   1      }
 100          
 101          void keyscan()
 102          {
 103   1              rd=0;
 104   1              if(s1==0)
 105   1              {
 106   2                      delay(5);
 107   2                      if(s1==0)
 108   2                      {
 109   3                              while(!s1);
 110   3                              wei++;
 111   3                              if(wei==1)
 112   3                              {
 113   4                                      TR0=0;
 114   4                                      write_com(0x0f);
 115   4                                      write_com(0x80+0x40+10);
 116   4                              }
 117   3                              if(wei==2)
C51 COMPILER V8.08   TIME                                                                  10/05/2008 18:43:22 PAGE 3   

 118   3                              {
 119   4                                      write_com(0x80+0x40+7);
 120   4                              }
 121   3                              if(wei==3)
 122   3                              {
 123   4                                      write_com(0x80+0x40+4);
 124   4                              }
 125   3                              if(wei==4)
 126   3                              {
 127   4                                      wei=0;
 128   4                                      write_com(0x0c);
 129   4                                      TR0=1;
 130   4                              }
 131   3      
 132   3                      }
 133   2              }
 134   1              if(wei!=0)
 135   1                      {
 136   2                              if(s2==0)
 137   2                              {
 138   3                                      delay(5);
 139   3                                      if(s2==0)
 140   3                                      {
 141   4                                              while(!s2);
 142   4                                              if(wei==1)
 143   4                                              {
 144   5                                                      miao++;
 145   5                                                      if(miao==60)miao=0;
 146   5                                                      write_time(6,miao);write_com(0x80+0x40+10);
 147   5                                              }
 148   4                                              if(wei==2)
 149   4                                              {
 150   5                                                      fen++;
 151   5                                                      if(fen==60)fen=0;
 152   5                                                      write_time(3,fen);write_com(0x80+0x40+7);
 153   5                                              }
 154   4                                              if(wei==3)
 155   4                                              {
 156   5                                                      shi++;
 157   5                                                      if(shi==24)shi=0;
 158   5                                                      write_time(0,shi);write_com(0x80+0x40+4);
 159   5                                              }
 160   4                                              
 161   4                                      }
 162   3                              }
 163   2                      }       
 164   1              
 165   1      }
 166          
 167          void wenreset()
 168          {
 169   1              uint i;
 170   1              dq=0;
 171   1              delay(1);
 172   1              dq=1;
 173   1              i=4;
 174   1              while(i>0)i--;
 175   1      
 176   1      }
 177          void wenspond()
 178          {
 179   1              uint i;
C51 COMPILER V8.08   TIME                                                                  10/05/2008 18:43:22 PAGE 4   

 180   1              while(dq);
 181   1              while(!dq);
 182   1              i=4;
 183   1              while(i>0)i--;
 184   1      }
 185          bit wenrdbit()
 186          {
 187   1              uint i;
 188   1              bit b;
 189   1              dq=0;
 190   1              i++;
 191   1              dq=1;
 192   1              i++;i++;
 193   1              b=dq;
 194   1              i=8;
 195   1              while(i>0)i--;
 196   1              return(b);
 197   1      }
 198          uchar wenrdbyte()
 199          {
 200   1              uchar i,j,b;
 201   1              b=0;
 202   1              for(i=1;i<=8;i++)
 203   1              {
 204   2                      j=wenrdbit();
 205   2                      b=(j<<7)|(b>>1);
 206   2              }
 207   1              return(b);
 208   1      }
 209          void wenwrbyte(uchar b)
 210          {
 211   1              uint i;
 212   1              uchar j;
 213   1              bit btmp;
 214   1              for(j=1;j<=8;j++)
 215   1              {
 216   2                      btmp = b&0x01;
 217   2                      b = b>>1;               
 218   2                      if (btmp)
 219   2                      {
 220   3                              dq = 0;
 221   3                              i++;i++;        
 222   3                              dq = 1;
 223   3                              i = 8;
 224   3                              while(i>0) i--; 
 225   3                      }
 226   2                      else
 227   2                      {
 228   3                              dq = 0;                 
 229   3                              i = 8;
 230   3                              while(i>0) i--; 
 231   3                              dq = 1;
 232   3                              i++;
 233   3                              i++;
 234   3                      }
 235   2              }
 236   1      }
 237          void wenconvert()
 238          {
 239   1              wenreset();
 240   1              wenspond();
 241   1              delay(1);
C51 COMPILER V8.08   TIME                                                                  10/05/2008 18:43:22 PAGE 5   

 242   1              wenwrbyte(0xcc);
 243   1              wenwrbyte(0x44);
 244   1      }
 245          uint wenrdtemp()
 246          {
 247   1              wenreset();
 248   1              wenspond();
 249   1              delay(1);
 250   1              wenwrbyte(0xcc);
 251   1              wenwrbyte(0xbe);
 252   1              tpl=wenrdbyte();
 253   1              tpm=wenrdbyte();
 254   1              wendu=((tpm&0x07)<<4)|((tpl&0xf0)>>4);
 255   1              
 256   1      
 257   1      
 258   1      
 259   1      //某一资料上的转换代码 可能是华氏转摄氏
 260   1      /*      wendu=tpm;                                                               
 261   1              wendu<<8;
 262   1              wendu=wendu|tpl;
 263   1              wendu=wendu*0.0625;wendu=wendu*10+0.5;                     */
 264   1              return(wendu);          
 265   1              
 266   1      
 267   1      
 268   1      }
 269          
 270          
 271          
 272          
 273          void main()
 274          {
 275   1              init();
 276   1         
 277   1              
 278   1              while(1)
 279   1              {
 280   2                      
 281   2      
 282   2                      keyscan();
 283   2      
 284   2              };                       
 285   1              
 286   1      
 287   1      }
 288          
 289          void timer() interrupt 1
 290          {
 291   1              TH0=(65536-50000)/256;
 292   1              TL0=(65536-50000)%256;
 293   1              count++;
 294   1              if(count==18)
 295   1              {       
 296   2                      count=0;
 297   2                      miao++;
 298   2                      if(miao==60)
 299   2                      {
 300   3                              miao=0;
 301   3                              fen++;
 302   3                              if(fen==60)
 303   3                              {
C51 COMPILER V8.08   TIME                                                                  10/05/2008 18:43:22 PAGE 6   

 304   4                                      fen=0;
 305   4                                      shi++;
 306   4                                      if(shi==24)shi=0;
 307   4                                      write_time(0,shi);
 308   4                              }
 309   3                              write_time(3,fen);
 310   3                      }
 311   2                      write_time(6,miao);
 312   2              }
 313   1                               wenconvert();
 314   1                       
 315   1              write_wendu(12,wenrdtemp());
 316   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    817    ----
   CONSTANT SIZE    =     20    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     10       1
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       2
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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