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

📄 ds18b20.lst

📁 自己的平时一些制作 现在整理一下 与大家一起分享
💻 LST
📖 第 1 页 / 共 2 页
字号:
 137   1              uchar i;
 138   1              for(i=0;i<8;i++)
 139   1              {
 140   2                      DQ=0;
 141   2                      _nop_();
 142   2                      _nop_();
 143   2                      _nop_();
 144   2                      DQ=1;             //释放总线
 145   2                      //delay15us();  注意不需要
 146   2                      if(DQ==0)          //如果读到的是0
 147   2                      {
 148   3                              readdata=readdata&0x7f;
 149   3                              delay60us();
 150   3                      }
 151   2                      else                    //读到的是1
 152   2                      {
 153   3                              readdata=readdata|0x80;
 154   3                              delay60us();
 155   3                      }
 156   2                      if(i<7)
 157   2                      
 158   2                      readdata=_cror_(readdata,1);
 159   2              }
 160   1              return readdata;
 161   1      }
 162          
 163          /*************************************************************
 164          **功能:温度处理函数                                                                                     **
 165          **参数:无返回                                                                                          **
 166          *************************************************************/
 167          void temperature_process(uchar low,uchar high)
 168          {
 169   1              uint temp1,temp2,temp3;
 170   1              if(high&0x80)//判断正负
 171   1              {
 172   2              flag=1;
 173   2      
 174   2              temp3=temp3|high;
 175   2              temp3=temp3&0x00ff;
 176   2              temp3=temp3<<8;
 177   2              temp1=temp3;
 178   2      
 179   2              temp1=temp1|low;
C51 COMPILER V7.01  DS18B20                                                                07/17/2007 14:39:09 PAGE 4   

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

 242   1               zhen_temp[3]='\0';
 243   1               for(i=0;i<2;i++)
 244   1                      if(zhen_temp[0]=='0')
 245   1                              {zhen_temp[0]=zhen_temp[1];
 246   2                              zhen_temp[1]=zhen_temp[2];
 247   2                              zhen_temp[2]='\0';
 248   2                              }
 249   1                      else
 250   1                              break;
 251   1      }
 252          /****************************************/
 253          //serial_set func
 254          void serial_set(void)
 255          {
 256   1              
 257   1              SCON=0x50;
 258   1              TMOD=TMOD&0x0f;
 259   1              TMOD=TMOD|0x20;
 260   1              TH1=0xfd;
 261   1              TL1=0xfd;
 262   1      
 263   1              TR1=1;
 264   1              TI=1;  //用PRINTF时,TI要置1
 265   1      }


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