找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4421|回復: 0
打印 上一主題 下一主題
收起左側(cè)

糧倉溫度巡檢報警系統(tǒng) 單片機多機通訊 自動巡檢程序和仿真

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:137190 發(fā)表于 2016-8-20 20:50 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
糧倉溫度巡檢報警系統(tǒng)原理圖如下

下面是溫度巡檢報警系統(tǒng)部分源程序
  1. #include <reg52.h>
  2. #include <18b20.h>
  3. /*
  4. sbit DS0=P1^0;           //define interface
  5. sbit DS1=P1^1;           //define interface
  6. sbit DS2=P1^2;           //define interface
  7. sbit DS3=P1^3;           //define interface
  8. sbit DS4=P1^4;           //define interface
  9. sbit DS5=P1^5;           //define interface
  10. */
  11. #define BIT1(x) (1<<x)
  12. #define DS P1
  13. #define NBIT1(x) ~BIT1(x)

  14. uchar No_number;
  15. //uchar DS;
  16. uint temp;             // variable of temperature
  17. void dsreset(uchar m)       //send reset and initialization command
  18. {
  19.   uint i;
  20.   DS&=NBIT1(m);
  21.     //DS&=BIT0(x);
  22.   i=103;
  23.   while(i>0)i--;//>480us,reset
  24.   DS|=BIT1(m);//keep free
  25.   i=4;
  26.   while(i>0)i--;
  27. }

  28. bit tmpreadbit(uchar m)       //read a bit
  29. {
  30.    uint i;
  31. //   uchar a;
  32.    bit dat;
  33.    DS&=NBIT1(m);i++;          //i++ for delay
  34.    DS|=BIT1(m);
  35.    //a=DS;
  36.     i++;i++;//讀時間片,要大于60us
  37.    if(DS&BIT1(m))
  38.      dat=1;
  39.     else
  40.      dat=0;
  41.    i=8;while(i>0)i--;
  42.    return (dat);
  43. }

  44. uchar tmpread(uchar m)   //read a byte date
  45. {
  46.   uchar i,j,dat;
  47.   dat=0;
  48.   for(i=1;i<=8;i++)
  49.   {
  50.     j=tmpreadbit(m);
  51.     dat=(j<<7)|(dat>>1);   //讀出的數(shù)據(jù)最低位在最前面,這樣剛好一個字節(jié)在DAT里
  52.   }
  53.   return(dat);
  54. }

  55. void tmpwritebyte(uchar dat,uchar m)   //write a byte to ds18b20
  56. {
  57.   uint i;
  58.   uchar j;
  59.   bit testb;
  60.   for(j=1;j<=8;j++)
  61.   {
  62.     testb=dat&0x01;//取最低位
  63.     dat=dat>>1;
  64.     if(testb)     //write 1
  65.     {
  66.       //DS=0;
  67.           DS&=NBIT1(m);
  68.       i++;i++;
  69.       DS|=BIT1(m);
  70.       i=8;while(i>0)i--;
  71.     }
  72.     else
  73.     {
  74.       //DS=0;       //write 0
  75.           DS&=NBIT1(m);
  76.       i=8;while(i>0)i--;//寫0要保持低電平60us
  77.       //DS=1;
  78.           DS|=BIT1(m);
  79.       i++;i++;
  80.     }

  81.   }
  82. }

  83. void tmpchange(uchar m)  //DS18B20 begin change
  84. {
  85.   dsreset(m);
  86.   delay(1);
  87.   tmpwritebyte(0xcc,m);  // address all drivers on bus
  88.   tmpwritebyte(0x44,m);  //  initiates a single temperature conversion
  89. }

  90. uint tmp(uchar m)               //get the temperature
  91. {
  92.   float tt;
  93.   uchar a,b;
  94.   dsreset(m);
  95.   delay(1);
  96.   tmpwritebyte(0xcc,m);
  97.   tmpwritebyte(0xbe,m);
  98.   a=tmpread(m);
  99.   b=tmpread(m);
  100.   temp=b;
  101.   temp<<=8;             //two byte  compose a int variable
  102.   temp=temp|a;
  103.   tt=temp*0.0625;
  104.   temp=tt*10+0.5;
  105.   return temp;
  106. }
復制代碼

多機通訊倉庫測溫.zip

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

整機電路圖 - 副本.rar

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

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏4 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

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

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

快速回復 返回頂部 返回列表