ARDUINO RTC PROGRAM

THE COMPONENT REQUIRED : ARDUINO UNO/ ARDUINO DEUMILANOVE
RTC REQUIRED:SparkFun Real Time Clock Module - BOB-12708 - SparkFun Electronics OR ANY WITH 12C INTERFACE
PIN CONNECTION :Real Time Clock DS1307 (RTC) + Arduino
simple code write date/ time in to RTC . It worked for me .i can also able to syn gps time date. :smiley: :slight_smile:

//Arduino 1.0+ Only
//Arduino 1.0+ Only

#include "Wire.h"
#define DS1307_ADDRESS 0x68

void setup(){
  Wire.begin();
  Serial.begin(9600);
}

void loop(){
  printDate();
  delay(100);
}

byte bcdToDec(byte val)  {
// Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

void printDate(){

  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);

  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 7);

  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());


// this code wil write user define time, date . whenever CPU reset the RTC read data from default. If we syn with gps it read data from GPS.
  /*int second = 12;
  int minute = 30;
  int hour = 21;
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay =2;
  int month =11;
  int year = 12;
*/
  
  Serial.print(month);
  Serial.print("/");
  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);

}

That's cool, I guess.

AJITnayak:
simple code write date/ time in to RTC . It worked for me .i can also able to syn gps time date. :smiley: :slight_smile:

I'm sorry, I don't understand the question.

Cool piece of Code but I see no GPS Libs... or for that matter code to use them or is that why you posted it... For suggestions?

Bob

can some one share me the code for syn gps to RTC time.
problems:
1)How to check i have written RTC time properly or not??
2) when ever i write code for RTC when try to open serial monitor i will found the date and time what have set it for.
why cant it update the RTC time to last stored

syntax program:
get_time(); get present time from rtc
get_previous_time();store present value in variable called previous
set_time();write previous time to RTC

print_time();Print the set time