找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 2123|回復(fù): 1
收起左側(cè)

基于單片機(jī)的水溫控制系統(tǒng)

[復(fù)制鏈接]
ID:319133 發(fā)表于 2018-12-20 14:40 | 顯示全部樓層 |閱讀模式
  1. #include<reg52.h>
  2. #include<intrins.h>
  3. #include<wendu.h>

  4. uchar temget()
  5. {
  6.     uchar low,high;
  7.     int temp;
  8.         float temperature;

  9.         dsinit();
  10.         write(0xcc);
  11.         write(0x44);
  12.         Delay_us(100);

  13.         dsinit();
  14.         write(0xcc);
  15.         write(0xbe);
  16.         Delay_us(100);

  17.     low=read();
  18.         high=read();       

  19.         temp=((high<<8)|low);
  20.         temperature=temp*0.0625;//分辨率是0.0625

  21. //        temp=high<<4;
  22. //        temp|=(low>>4);        //顯示整數(shù)

  23.     return temperature;
  24. }

  25. uchar read()
  26. {
  27.         uchar i;
  28.         uchar dat;
  29.         for(i=0;i<8;i++)
  30.         {
  31.                 DQ=0;
  32.                 _nop_();_nop_();_nop_();_nop_();_nop_();
  33.                 dat>>=1;
  34.                 DQ=1;
  35.                 if(DQ==1)
  36.                 {
  37.                                 dat|=0x80;
  38.                 }
  39.                 Delay_us(100);                       
  40.         }
  41.         return dat;
  42. }

  43. void write(uchar dat)
  44. {
  45.                 uchar i;
  46.                 for(i=0;i<8;i++)
  47.                 {
  48.                                 DQ=0;
  49.                                 DQ=dat&0x01;
  50.                                 Delay_us(70);
  51.                                 DQ=1;
  52.                                 dat>>=1;
  53.                 }
  54. }



  55. void dsinit()
  56. {
  57.                 DQ=0;
  58.                 Delay_us(80);
  59.                 DQ=1;
  60.                 Delay_us(80);               
  61. }


  62. void Delay_us(uchar us)
  63. {
  64.         while(us--);        
  65. }

復(fù)制代碼


捕獲.PNG

51黑論壇_temp.rar

50.54 KB, 下載次數(shù): 41, 下載積分: 黑幣 -5

回復(fù)

使用道具 舉報(bào)

ID:1 發(fā)表于 2018-12-21 01:05 | 顯示全部樓層
不要發(fā)布重復(fù)內(nèi)容
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表