找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3616|回复: 0
收起左侧

粮仓温度巡检报警系统 单片机多机通讯 自动巡检程序和仿真

[复制链接]
ID:137190 发表于 2016-8-20 20:50 | 显示全部楼层 |阅读模式
粮仓温度巡检报警系统原理图如下
113808pr8myzp38p9ssjpl.gif 0.png
下面是温度巡检报警系统部分源程序
  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);   //读出的数据最低位在最前面,这样刚好一个字节在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, 下载次数: 61, 下载积分: 黑币 -5

整机电路图 - 副本.rar

26.91 KB, 下载次数: 55, 下载积分: 黑币 -5

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表