Read TCN75A Temperature Sensor

///////////////////////////////////////////////////
//Project 6.03 Read TCN75A Temperature Sensor
#include <Wire.h> 
int tempreg = 0;        
float temperature = 0;   
byte address = 72;

void setup(){
  Serial.begin(9600);
  Wire.begin();
  //Do some setup for the sensor
  // Set the resolution of the measurement
  Wire.beginTransmission(address);
  // point to Configuration Register
  Wire.write(0x01);  
  // set the resolution 
  Wire.write(0x60);  
  // ends the command 
  Wire.endTransmission();      
  // points to the Temperature Register 
  Wire.beginTransmission(address); 
  Wire.write(0x00);           
  Wire.endTransmission();       
}

void loop(){
  // Receives data from the Temperature Register
  Wire.requestFrom(address,byte(2));
  tempreg = Wire.read();      
  tempreg= tempreg << 8;     
  tempreg |= Wire.read();  
  tempreg = tempreg >> 4; 
  // Calculate the temperature
  temperature =( float ) tempreg / 16;
  // Display the temperature in the Serial Monitor
  Serial.print("Temp F = ");
  Serial.print(temperature*9/5 + 32,2);
  Serial.print("   ");
  Serial.print("Temp C = ");
  Serial.println(temperature, 2);
  delay(500);
}
///////////////////////////////////////////////////

沧海扬帆 发表于08-10 09:18 浏览65535次
分享到:

已有0条评论

暂时还没有回复哟,快来抢沙发吧

添加一条新评论

只有登录用户才能评论,请先登录注册哦!

话题作者

沧海扬帆
沧海扬帆(上将)
金币:46个|学分:9110个
立即注册
畅学电子网,带你进入电子开发学习世界
专业电子工程技术学习交流社区,加入畅学一起充电加油吧!

x

畅学电子网订阅号