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

📄 ds18b20.lst

📁 自己的平时一些制作 现在整理一下 与大家一起分享
💻 LST
📖 第 1 页 / 共 2 页
字号:
 174          **功能:温度处理函数                                                                                     **
 175          **参数:无返回                                                                                          **
 176          *************************************************************/
 177          void temperature_process(uchar low,uchar high)
 178          {
 179   1              uint temp1,temp2,temp3;
C51 COMPILER V8.02   DS18B20                                                               05/03/2007 09:16:11 PAGE 4   

 180   1              if(high&0x80)//判断正负
 181   1              {
 182   2              flag=1;
 183   2      
 184   2              temp3=temp3|high;
 185   2              temp3=temp3&0x00ff;
 186   2              temp3=temp3<<8;
 187   2              temp1=temp3;
 188   2      
 189   2              temp1=temp1|low;
 190   2              
 191   2              temp1=(temp1^0xffff);
 192   2              temp1=temp1+1;   //取反加1
 193   2              low=temp1&0x000f;
 194   2              high=temp1>>4;
 195   2                      process(high,low);
 196   2              }
 197   1              else
 198   1              {
 199   2      
 200   2                      flag=0;          //zhen
 201   2                      temp1=high;
 202   2                      temp2=low;
 203   2                      temp1=temp1<<4;
 204   2                      temp2=temp2>>4;
 205   2                      temp3=temp1|temp2;
 206   2                      high=temp3;
 207   2                      low=low&0x0f;
 208   2                      process(high,low);
 209   2              
 210   2              }
 211   1      }
 212          /*************************************************************
 213          **功能:数值处理函数                                                                                     **
 214          **参数:无返回                                                                                          **
 215          *************************************************************/
 216          void process(unsigned char high,unsigned char low)
 217          {
 218   1               uint temp1;
 219   1               uchar i;
 220   1               temp1=low*625;
 221   1               xiaoshu_temp[0]=temp1/1000+'0';
 222   1               xiaoshu_temp[1]=temp1/100%10+'0';
 223   1               xiaoshu_temp[2]=temp1%100/10+'0';
 224   1               xiaoshu_temp[3]=temp1%10+'0';
 225   1               xiaoshu_temp[4]='\0';
 226   1               
 227   1                      if(xiaoshu_temp[3]=='0')
 228   1                      {
 229   2                              xiaoshu_temp[3]='\0';
 230   2                              if(xiaoshu_temp[2]=='0')
 231   2                                      {
 232   3                                              xiaoshu_temp[2]='\0';
 233   3                                              if(xiaoshu_temp[1]=='0')
 234   3                                              {
 235   4                                                      xiaoshu_temp[1]='\0';
 236   4                                                      if(xiaoshu_temp[0]=='0')
 237   4                                                      {
 238   5                                                              xiaoshu_temp[0]='\0';
 239   5                                                              dot_dis=0;
 240   5                                                      }
 241   4                                                      
C51 COMPILER V8.02   DS18B20                                                               05/03/2007 09:16:11 PAGE 5   

 242   4                                                              
 243   4                                              }
 244   3                                      }
 245   2                                              
 246   2                      }
 247   1              
 248   1               
 249   1               zhen_temp[0]=high/100+'0';
 250   1               zhen_temp[1]=high%100/10+'0';
 251   1               zhen_temp[2]=high%10+'0';
 252   1               zhen_temp[3]='\0';
 253   1               for(i=0;i<2;i++)
 254   1                      if(zhen_temp[0]=='0')
 255   1                              {zhen_temp[0]=zhen_temp[1];
 256   2                              zhen_temp[1]=zhen_temp[2];
 257   2                              zhen_temp[2]='\0';
 258   2                              }
 259   1                      else
 260   1                              break;
 261   1      }
 262          /****************************************/
 263          //serial_set func
 264          void serial_set(void)
 265          {
 266   1              
 267   1              SCON=0x50;
 268   1              TMOD=TMOD&0x0f;
 269   1              TMOD=TMOD|0x20;
 270   1              TH1=0xfd;
 271   1              TL1=0xfd;
 272   1      
 273   1              TR1=1;
 274   1              TI=1;  //用PRINTF时,TI要置1
 275   1      }
 276          void ds18b20_process(void)
 277          {               uchar *str="temperature is ";
 278   1                      uchar i;
 279   1                      ds18b20_init();
 280   1                      
 281   1      
 282   1                      ds18b20_writecommand(0xcc);
 283   1                      ds18b20_writecommand(0x44);      //转换
 284   1                      TR0=1;
 285   1                      if(ds18b20_over)
 286   1                      {
 287   2                              ds18b20_over=0;
 288   2                              ds18b20_init();
 289   2                              ds18b20_writecommand(0xcc);
 290   2                              ds18b20_writecommand(0xbe);       //读
 291   2      
 292   2      
 293   2                              for(i=0;i<2;i++)
 294   2                              {
 295   3              
 296   3                                      temp[i]=ds18b20_readdata();
 297   3                      
 298   3                              }
 299   2                              ds18b20_init();
 300   2                              temperature_process(temp[0],temp[1]);
 301   2              
 302   2                              if(!flag) //正
 303   2                              {
C51 COMPILER V8.02   DS18B20                                                               05/03/2007 09:16:11 PAGE 6   

 304   3                                      GotoXY(0,1);
 305   3                                      Print(zhen_temp);
 306   3                                      if(dot_dis)     
 307   3                                      Print(".");
 308   3                                      Print(xiaoshu_temp);
 309   3                              }
 310   2                              else   //负
 311   2                              {
 312   3                                      GotoXY(0,1);
 313   3                                      Print("-");
 314   3                                      Print(zhen_temp);       
 315   3                                      Print(".");
 316   3                                      Print(xiaoshu_temp);
 317   3      
 318   3                              }
 319   2                      }
 320   1      }
 321          
 322          void time0(void) interrupt 1 using 3
 323          {
 324   1              ET0=0;
 325   1              TR0=0;
 326   1              if(timeout)
 327   1              {
 328   2                      TH0=0;
 329   2                      TL0=0;
 330   2                      timeout--;
 331   2                      TR0=1;
 332   2              }
 333   1              else
 334   1              {       ds18b20_over=1;
 335   2                      timeout=20;
 336   2              }
 337   1              ET0=1;
 338   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    690    ----
   CONSTANT SIZE    =     20    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     15      10
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      3    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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