-
大小: 33KB文件类型: .zip金币: 2下载: 2 次发布日期: 2021-06-02
- 语言: 其他
- 标签: arduino OneWire库 DallasTemper
资源简介
arduino的DallasTemperature库和OneWire库,正确无误的!
代码片段和文件信息
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License or (at your option) any later version.
#include “DallasTemperature.h“
extern “C“ {
#include “arduino.h“
// #include “WConstants.h“
}
DallasTemperature::DallasTemperature(OneWire* _oneWire)
#if REQUIRESALARMS
: _AlarmHandler(&defaultAlarmHandler)
#endif
{
_wire = _oneWire;
devices = 0;
parasite = false;
conversionDelay = TEMP_9_BIT;
}
// initialize the bus
void DallasTemperature::begin(void)
{
DeviceAddress deviceAddress;
_wire->reset_search();
while (_wire->search(deviceAddress))
{
if (validAddress(deviceAddress))
{
if (!parasite && readPowerSupply(deviceAddress)) parasite = true;
ScratchPad scratchPad;
readScratchPad(deviceAddress scratchPad);
if (deviceAddress[0] == DS18S20MODEL) conversionDelay = TEMP_12_BIT; // 750 ms
else if (scratchPad[CONFIGURATION] > conversionDelay) conversionDelay = scratchPad[CONFIGURATION];
devices++;
}
}
}
// returns the number of devices found on the bus
uint8_t DallasTemperature::getDeviceCount(void)
{
return devices;
}
// returns true if address is valid
bool DallasTemperature::validAddress(uint8_t* deviceAddress)
{
return (_wire->crc8(deviceAddress 7) == deviceAddress[7]);
}
// finds an address at a given index on the bus
// returns true if the device was found
bool DallasTemperature::getAddress(uint8_t* deviceAddress uint8_t index)
{
uint8_t depth = 0;
_wire->reset_search();
while (depth <= index && _wire->search(deviceAddress))
{
if (depth == index && validAddress(deviceAddress)) return true;
depth++;
}
return false;
}
// attempt to determine if the device at the given address is connected to the bus
bool DallasTemperature::isConnected(uint8_t* deviceAddress)
{
ScratchPad scratchPad;
return isConnected(deviceAddress scratchPad);
}
// attempt to determine if the device at the given address is connected to the bus
// also allows for updating the read scratchpad
bool DallasTemperature::isConnected(uint8_t* deviceAddress uint8_t* scratchPad)
{
readScratchPad(deviceAddress scratchPad);
return (_wire->crc8(scratchPad 8) == scratchPad[SCRATCHPAD_CRC]);
}
// read device‘s scratch pad
void DallasTemperature::readScratchPad(uint8_t* deviceAddress uint8_t* scratchPad)
{
// send the command
_wire->reset();
_wire->select(deviceAddress);
_wire->write(READSCRATCH);
// read the response
// byte 0: temperature LSB
scratchPad[TEMP_LSB] = _wire->read();
// byte 1: temperature MSB
scratchPad[TEMP_MSB] = _wire->read();
// byte 2: high alarm temp
scratchPad[HIGH_ALARM_TEMP] = _wire->read();
// byte 3: low alarm temp
scratchPad[LOW_ALARM_TEMP] = _wire->read();
// byte 4:
// DS18S20: store for crc
// DS18B20 & DS1822: configuration regis
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-03-28 07:33 DallasTemperature\
文件 1290 2016-03-28 07:33 DallasTemperature\keywords.txt
文件 1850 2016-03-28 07:33 DallasTemperature\README
文件 5759 2016-03-28 07:33 DallasTemperature\DallasTemperature.h
文件 17173 2016-03-28 07:33 DallasTemperature\DallasTemperature.cpp
目录 0 2016-03-28 07:33 DallasTemperature\examples\
目录 0 2016-03-28 07:33 DallasTemperature\examples\Tester\
文件 3652 2016-03-28 07:33 DallasTemperature\examples\Tester\Tester.pde
目录 0 2016-03-28 07:33 DallasTemperature\examples\Single\
文件 3991 2016-03-28 07:33 DallasTemperature\examples\Single\Single.pde
目录 0 2016-03-28 07:33 DallasTemperature\examples\Simple\
文件 927 2016-03-28 07:33 DallasTemperature\examples\Simple\Simple.pde
目录 0 2016-03-28 07:33 DallasTemperature\examples\Multiple\
文件 4726 2016-03-28 07:33 DallasTemperature\examples\Multiple\Multiple.pde
目录 0 2016-03-28 07:33 DallasTemperature\examples\AlarmHandler\
文件 3930 2016-03-28 07:33 DallasTemperature\examples\AlarmHandler\AlarmHandler.pde
目录 0 2016-03-28 07:33 DallasTemperature\examples\Alarm\
文件 4325 2016-03-28 07:33 DallasTemperature\examples\Alarm\Alarm.pde
目录 0 2016-03-28 07:33 OneWire\
文件 819 2016-03-28 07:33 OneWire\keywords.txt
文件 7206 2016-03-28 07:33 OneWire\OneWire.h
文件 16361 2016-03-28 07:33 OneWire\OneWire.cpp
目录 0 2016-03-28 07:33 OneWire\examples\
目录 0 2016-03-28 07:33 OneWire\examples\DS250x_PROM\
文件 4098 2016-03-28 07:33 OneWire\examples\DS250x_PROM\DS250x_PROM.pde
目录 0 2016-03-28 07:33 OneWire\examples\DS2408_Switch\
文件 1907 2016-03-28 07:33 OneWire\examples\DS2408_Switch\DS2408_Switch.pde
目录 0 2016-03-28 07:33 OneWire\examples\DS18x20_Temperature\
文件 2763 2016-03-28 07:33 OneWire\examples\DS18x20_Temperature\DS18x20_Temperature.pde
- 上一篇:汇编课程设计 :简单计算器的设计与实现
- 下一篇:Waifu2x 视频处理
相关资源
- Arduino nano 工程文件
- Arduino教程 Lesson 之--自制风扇
- 基于Arduino的智能环境监控系统设计
- 基于Arduino和Machtalk的温棚环境监测系
- arduino pca9685多舵机同时控制案例
- arduino技术内幕
- Arduino电子设计实战指南.零基础篇_超
- 物联网智能家居平台DIY:ARDUINO 物联网
- 实验1.zip arduino跑马灯led灯实验,串口
- opencat所有资料.zip
- arduino主机,stm8从机。I2C测试 。每次
- DS18B20_Serial_println.ino
- ps2手柄arduino库文件
- 基于手机蓝牙的arduino遥控小车
- arduino中的can库函数
- 密码+指纹锁资料包.rar
- 贝壳物联arduino esp8266 demo版本
- HMC5883L罗盘指南针模块库文件及中英文
- arduino 小贱钟源码及教程
- Atom-TMC2208Pilot在Arduino上运行的应用程
- 写字机制作方案
- PID-增量式PID和位置式PID算法实现和
- Building Wireless Sensor Networks Using Arduin
- vc控制Arduino,实现串口通信
- Arduino入门经典
- Arduino所有库.zip
- 基于STM32和arduino的MPU9250九轴传感器代
- GY-9960模块Keil 和Arduino驱动程序
- ILI9486 3.5TFT液晶屏Arduino驱动
- [高清文字版]Arduino开发从零开始学
评论
共有 条评论