SHARE
TWEET

Untitled

a guest Apr 5th, 2017 8 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <avr/io.h>
  2. #include <stdio.h>
  3. #include "i2cmaster.h"
  4.  
  5. #define hih9131w  0x4E  //write mode
  6. #define hih9131r  0x4F  //read mode
  7.  
  8. void waterSense(void);
  9. void THSense(void);
  10.  
  11. unsigned char humL;
  12. unsigned char humH;
  13. unsigned short hum;
  14. unsigned char tempL;
  15. unsigned char tempH;
  16. unsigned short temp;
  17. unsigned short humN;
  18. unsigned short tempN;
  19.  
  20.  
  21. int main(void)
  22. {
  23.         i2c_init();                             // initialize I2C library
  24.         while(1) {
  25.             THSense();
  26.         }
  27. }
  28.  
  29. void THSense(void) {
  30.     i2c_start_wait(hih9131w);               // measurement request
  31.     i2c_stop();                             // set stop condition = release bus
  32.     i2c_start_wait(hih9131r);               // set device address and read mode
  33.     humH = i2c_readAck();                   // read one byte from EEPRO M
  34.     humL = i2c_readAck();
  35.     tempH = i2c_readAck();
  36.     tempL = i2c_readNak();
  37.     i2c_stop();
  38.     hum = (humH << 8) + humL;
  39.     temp = (tempH << 8) + tempL;
  40.     hum = (hum << 2);
  41.     hum = (hum >> 2);
  42.     temp = (temp >> 2);
  43.     humN = (hum/16382.0) * 100;
  44.     tempN = ((temp/16382.0) * 165) - 40;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top