imranahmed
Advanced Member level 3
- Joined
- Dec 4, 2011
- Messages
- 817
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,298
- Location
- Karachi,Pakistan
- Activity points
- 6,493
Please let me know I found a code for RTC DS1307 I want to understand some coding in it.
What are they doing bitwise operation here
Serial.print((month & 0x10)>>4); //month & 0x10 why 0x10 is used here
Serial.print(month & 0x0F);
Serial.print((date & 0x70)>>4); //date & 0x70 why 0x70 is used here
Serial.print(date & 0x0F);
What are they doing bitwise operation here
Serial.print((month & 0x10)>>4); //month & 0x10 why 0x10 is used here
Serial.print(month & 0x0F);
Serial.print((date & 0x70)>>4); //date & 0x70 why 0x70 is used here
Serial.print(date & 0x0F);
Code:
if(Wire.available() == 7) // slave may send less than requested
{
byte seconds = Wire.read(); // receive a byte as character
byte minutes = Wire.read(); // receive a byte as character
byte hours = Wire.read(); // receive a byte as character
byte day = Wire.read(); // receive a byte as character
byte date = Wire.read(); // receive a byte as character
byte month = Wire.read(); // receive a byte as character
byte year = Wire.read(); // receive a byte as character
// Print date to serial port
Serial.print("Date: ");
Serial.print((month & 0x10)>>4);
Serial.print(month & 0x0F);
Serial.print("/");
Serial.print((date & 0x70)>>4);
Serial.print(date & 0x0F);
Serial.print("/");
Serial.print((year & 0x70)>>4);
Serial.print(year & 0x0F);
// Print time to serial port
Serial.print(" Time: ");
Serial.print(hours);
Serial.print(":");
Serial.print((minutes & 0x70)>>4);
Serial.print(minutes & 0x0F);
Serial.print(":");
Serial.print((seconds & 0x70)>>4);
Serial.print(seconds & 0x0F);
Serial.println("");
}