SHARE
TWEET

Untitled

a guest Mar 29th, 2017 13 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 hih9131  0x27
  6.  
  7. void THSense(void);
  8.  
  9. int main(void)
  10. {
  11.     i2c_init();                             // initialize I2C library
  12.     THSense();
  13. }
  14.  
  15.  
  16. void THSense(void) {
  17.     unsigned char ret;
  18.  
  19.     // write 0x75 to EEPROM address 5 (Byte Write)
  20.     i2c_start_wait(hih9131+I2C_WRITE);     // set device address and write mode
  21.     i2c_write(0x05);                        // write address = 5
  22.     i2c_write(0x75);                        // write value 0x75 to EEPROM
  23.     i2c_stop();                             // set stop conditon = release bus
  24.  
  25.  
  26.     // read previously written value back from EEPROM address 5
  27.     i2c_start_wait(hih9131+I2C_WRITE);     // set device address and write mode
  28.  
  29.     i2c_write(0x05);                        // write address = 5
  30.     i2c_rep_start(hih9131+I2C_READ);       // set device address and read mode
  31.  
  32.     ret = i2c_readNak();                    // read one byte from EEPROM
  33.     i2c_stop();
  34. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top