Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1485267
  • 博文数量: 129
  • 博客积分: 1449
  • 博客等级: 上尉
  • 技术积分: 3048
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-24 18:36
文章分类

全部博文(129)

文章存档

2015年(3)

2014年(20)

2013年(65)

2012年(41)

分类: 嵌入式

2012-07-26 07:54:40



2.  

点击(此处)折叠或打开

  1. int read_temperature(int portnum, float *current_temp, u16 *usData)
  2. {
  3.   int count=0, i;
  4.   uchar family_id[MAXDEVICES][8], temp_H, temp_L;
  5.   char str[100];

  6.     owFamilySearchSetup(portnum, 0x00);
  7.     while (owNext(portnum, TRUE, FALSE)) {
  8.         count++;    //一定放于此,

  9.     owSerialNum(portnum, family_id[count], TRUE);
  10.     //array_hex(str, &family_id[count], 8);
  11.     //DBG("%d: %s\n", count, str);

  12. #if 1
  13.         if (ReadTemperature(portnum, family_id[count], current_temp, usData)) {
  14.         DBG(", Temperature = %5.1f, %5.1f \n", *current_temp, (*current_temp) * 9 / 5 + 32);
  15.     }
  16.     else
  17.         DBG("Error reading temperature, verify device present:%d\n", (int)owVerify(portnum, FALSE));

  18. #else
  19.         owTouchReset(portnum);
  20.         owTouchByte(portnum, 0xcc);
  21.         owTouchByte(portnum, 0x44);    //所有的传感器开始转换温度
  22.         msDelay(1000);

  23.         owTouchReset(portnum);
  24.         owTouchByte(portnum, 0x55);    //发送ROM匹配命令
  25.         for(i=0; i<8; i++)
  26.             owTouchByte(portnum, family_id[count]);

  27.         owTouchByte(portnum, 0xBE);    //读温度寄存器(共可读9个寄存器)前两个是温度
  28.         msDelay(20);

  29.         temp_L = owTouchByte(portnum, 0xff); //读取温度的低位, F2 01, F4 01, FE 01
  30.         temp_H = owTouchByte(portnum, 0xff); //读取温度的高位.
  31.         current_temp = (temp_H*256 + temp_L)*0.0625;
  32.         DBG(", %02X-%02X = %5.1f, %5.1f \n", temp_L, temp_H, current_temp, current_temp * 9 / 5 + 32);
  33. #endif
  34.   }

  35.   owTouchReset(portnum);

  36.     return 1;
  37. }


阅读(1443) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~