Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <stdio.h>
- #include "i2cmaster.h"
- #define hih9131w 0x4E //write mode
- #define hih9131r 0x4F //read mode
- void waterSense(void);
- void THSense(void);
- unsigned char humL;
- unsigned char humH;
- unsigned short hum;
- unsigned char tempL;
- unsigned char tempH;
- unsigned short temp;
- unsigned short humN;
- unsigned short tempN;
- int main(void)
- {
- i2c_init(); // initialize I2C library
- while(1) {
- THSense();
- }
- }
- void THSense(void) {
- i2c_start_wait(hih9131w); // measurement request
- i2c_stop(); // set stop condition = release bus
- i2c_start_wait(hih9131r); // set device address and read mode
- humH = i2c_readAck(); // read one byte from EEPRO M
- humL = i2c_readAck();
- tempH = i2c_readAck();
- tempL = i2c_readNak();
- i2c_stop();
- hum = (humH << 8) + humL;
- temp = (tempH << 8) + tempL;
- hum = (hum << 2);
- hum = (hum >> 2);
- temp = (temp >> 2);
- humN = (hum/16382.0) * 100;
- tempN = ((temp/16382.0) * 165) - 40;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement