REAL TIME CLOCK (RTC) USING SMD IC BQ32000 AND MSP430 LAUCHPAD (MSP430G25530


OUTPUT ON X-CTU SERIAL MONITOR



CIRCUIT




PROGRAM
//Here i am interfacing Real time clock with Arduino Uno and sends time to pc via serial port
//connect SDA---> P1_7, SCL---> P1_6
#include <Wire.h>
const int DS1307 = 0x68; // Address of DS1307 AND BQ32000 ARE SAME- see data sheets
byte second = 0;
byte minute = 0;
byte hour = 0;
byte weekday = 0;
byte monthday = 0;
byte month = 0;
byte year = 0;

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  delay(100);
setTime();
  Serial.print("HHH");
}
void loop()
{
  readTime();
  delay(1000);
}

byte bcdToDec(byte val)
{
  int msbdec=val/16*10; //gets decimel msb of BCD value(4 bits)
  int lsbdec = val%16;//gets decimel lsb of BCD value(4 bits)
  int total=msbdec+lsbdec;
  return (total);
    //return ((val/16*10) + (val%16));
}

void readTime()
{
  Wire.beginTransmission(DS1307);
  Wire.write(byte(0));
  Wire.endTransmission();
  Wire.requestFrom(DS1307, 7);
  second = bcdToDec(Wire.read());


  minute = bcdToDec(Wire.read());
  hour = bcdToDec(Wire.read());
  weekday = bcdToDec(Wire.read());
  monthday = bcdToDec(Wire.read());
  month = bcdToDec(Wire.read());
  year = bcdToDec(Wire.read());

   Serial.print(monthday);
    Serial.write('-');
    Serial.print(month );
    Serial.write('-');
    Serial.print(year);
    Serial.write('-');
    Serial.write('-');
 
     Serial.print(hour);
    Serial.write(':');
  Serial.print(minute);
    Serial.write(':');
  Serial.print(second);
  Serial.write(0xd);



}

void setTime() {

  // The following codes transmits the data to the RTC
  Wire.beginTransmission(DS1307);
  Wire.write(byte(0)); //starts sending data writing
  Wire.write(0x12);//second
  Wire.write(0x20); //minute
  Wire.write(0x15); //hour
  Wire.write(0x7); //weekday
  Wire.write(0x10);//monthday
  Wire.write(0x11);//month
  Wire.write(0x15);//year
  Wire.write(byte(0));
  Wire.endTransmission();
  // Ends transmission of data
}

NOTE
THIS PROGRAM WORK WITH RTC IC DS1307 (SUPPLY MUST BE 1.25*BATTERY VOLTAGE)