c - 通过地址连接 DS18B20

标签 c arduino hex

我有单线设备 DS18b20 的地址,我想通过在数组中声明其地址来连接它,并且我想调用地址数组的初始化程序是 onewire.select(array-Initializer),然后我想计算温度,但我得到 Data = 0 0 0 0

#include <OneWire.h>
OneWire ds(10);
//byte address[8];
byte data[12];
//int a;
byte i;
byte address[]={0x28,0xFF,0x6C,0xEA,0x62,0x16,0x4,0xE7};  

void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
}

void loop() {
    // put your main code here, to run repeatedly:
    ds.reset();
    ds.select(&address);
    ds.write(0x44);

    ds.reset();
    ds.select(address);
    ds.write(0xBE);

    Serial.print("DATA=");
    for (i=0;i<9;i++){
        Serial.print(" ");
        data[i]= ds.read();
        Serial.print(data[i],DEC);
        Serial.print(" ");
    }
    Serial.println();
    delay(1000);
} 

我也收到此错误:

no matching function for call to 'OneWire::select(byte (*)[8])

最佳答案

来自sources :

void OneWire::select( uint8_t rom[8])

尝试:

uint8_t address[]={0x28,0xFF,0x6C,0xEA,0x62,0x16,0x4,0xE7};  
ds.select(address);

C++ 能够识别变量类型。

关于c - 通过地址连接 DS18B20,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53537249/

相关文章:

c# - 将二进制数转换为 ascii 字符

c - 这是空操作还是其他什么?

c - 寻找 `COMPILE_WPRINTF` 的定义

c++ - C 和 C++ 中 bool 值的 sizeof 运算符的输出差异

c - 通过从 C 中的文件中获取输入来求无限整数的总和

c++ - 在类中初始化可变大小的数组

c - 逻辑或按位或可互换?

swift - Swift 中的浮点十六进制表示法

arduino - 从 SD 卡运行 arduino sketch

awk,小端顺序和 4 个十六进制数字