Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1.  
  2. #include <Wire.h>          
  3. #define eeprom 0x50      
  4.  
  5. byte B = 12;
  6. byte b = 0;
  7. unsigned int Direcion = 10;
  8.  
  9. void setup()
  10. {
  11.   Wire.begin();          
  12.   Serial.begin(9600);
  13.   delay(6);
  14. }
  15.  
  16. void loop(){
  17.  
  18.   Serial.print("Escribir ");
  19.   Serial.print(B, DEC);
  20.   Serial.print(" --> ");
  21.   Serial.print(B, HEX);
  22.   Serial.print(" HEX en ");
  23.   Serial.print(Direcion);
  24.   Serial.println();
  25.  
  26.   Wire.beginTransmission(eeprom);
  27.   Wire.write((int)(Direcion >> 8));  
  28.   Wire.write((int)(Direcion & 0xFF));
  29.   Wire.write(b);
  30.   Wire.endTransmission();
  31.   delay(5);    
  32.  
  33.  
  34.  
  35.   Serial.print("Leer direccion : ");
  36.   Serial.print(Direcion);
  37.   Serial.print(" ... ");
  38.   Wire.beginTransmission(eeprom);
  39.   Wire.write((int)(Direcion >> 8));   // MSB
  40.   Wire.write((int)(Direcion & 0xFF)); // LSB
  41.   Wire.endTransmission();
  42.   delay(5);
  43.   Wire.requestFrom(Direcion,1);
  44.   if (Wire.available()) {b = Wire.read();}
  45.   Serial.print(b, HEX);
  46.   Serial.print(" --> ");
  47.   Serial.print(b, DEC);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement