极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10267|回复: 5

18B20

[复制链接]
发表于 2013-5-27 21:45:49 | 显示全部楼层 |阅读模式
    求 这个库  <OneWire.h>,写18B20温度传感器。。。。急
回复

使用道具 举报

发表于 2013-5-27 22:15:13 | 显示全部楼层
本帖最后由 mbird 于 2013-5-27 22:17 编辑

OneWire_lib:http://playground.arduino.cc/Learning/OneWire
请自取
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-27 22:57:39 | 显示全部楼层
谢谢了,我需要的是18B20库。。。。
回复 支持 反对

使用道具 举报

发表于 2013-5-27 23:16:57 | 显示全部楼层
本帖最后由 mbird 于 2013-5-27 23:18 编辑

你~~~要不要往下拉(http://playground.arduino.cc/Learning/OneWire)
底下的這段CODE就是你要的.. for 18S20&18B20

放心用吧 我試過沒問題
=============================
#include <OneWire.h>

// DS18S20 Temperature chip i/o
OneWire ds(10);  // on pin 10

void setup(void) {
  // initialize inputs/outputs
  // start serial port
  Serial.begin(9600);
}

void loop(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
      Serial.print("No more addresses.\n");
      ds.reset_search();
      return;
  }

  Serial.print("R=");
  for( i = 0; i < 8; i++) {
    Serial.print(addr, HEX);
    Serial.print(" ");
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.print("CRC is not valid!\n");
      return;
  }

  if ( addr[0] == 0x10) {
      Serial.print("Device is a DS18S20 family device.\n");
  }
  else if ( addr[0] == 0x28) {
      Serial.print("Device is a DS18B20 family device.\n");
  }
  else {
      Serial.print("Device family is not recognized: 0x");
      Serial.println(addr[0],HEX);
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end

  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);   
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("P=");
  Serial.print(present,HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data = ds.read();
    Serial.print(data, HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print( OneWire::crc8( data, 8), HEX);
  Serial.println();
}
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-28 10:00:25 | 显示全部楼层
好吧。。。谢谢
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-28 10:32:24 | 显示全部楼层
能把这个《OneWire.h》库压缩发给我吗?
回复 支持 反对

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-29 09:32 , Processed in 0.041476 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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