Hola .yo lo estoy usando con los siguientes programas
para escribir la hora en el reloj
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
void setDateDs1307(
byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7 1=Lunes, 7=Domingo
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year // 0-99
)
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.endTransmission();
}
void setup()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
pinMode(13, OUTPUT);
// Cambiamos los parámetros como queramos
// Lo mejor es poner la hora del script 30 segundos antes que es lo que tarda el ordenador aproximadamente en compilar el programa
// Sólo es necesario compilar el script una vez
// El formato es de 24 horas
// Días de la semana lunes es 1 a domingo que es 7
// El formato de año son los dos últimos dígitos del año
//
// Una vez cargado el programa el led 13 parpadeará cada segundo, no debemos resetear.
second = 0;
minute = 20;
hour = 9;
dayOfWeek = 3;
dayOfMonth = 24;
month = 8;
year = 16;
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
//*/
}
void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
para leer l ahora una vez cargada
#include "Wire.h"// comunicacion I2C
#define DS1307_I2C_ADDRESS 0x68
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void getDateDs1307(byte *second,byte *minute,byte *hour,byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year)
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);///inicio I2C
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);//INICIO PEDIDO DE INFORMACION
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
Serial.begin(9600);
//lcd.begin(16, 2);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
String s, m, d, mth, h; ///VARIABLES IMPORTANTES
///void getDateDs1307(byte *second,byte *minute,byte *hour,byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year)//esta es la funcion que estamos llamando
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);//llamo a la fucion getDataDs1307
if (second < 10) { s = "0" + String(second); } else { s = String(second); }// segundos
if (minute < 10) { m = "0" + String(minute); } else { m = String(minute); }//minutos
h = String(hour);//hora
if (dayOfMonth < 10) { d = "0" + String(dayOfMonth); } else { d = String(dayOfMonth); }// dia del mes
if (month < 10) { mth = "0" + String(month); } else { mth = String(month); }//mes
char* days[] = { "NA", "LUNES", "MARTES", "MIERCOLES", "JUEVES", "VIERNES", "SABADO", "DOMINGO" };
// lcd.clear(); //lcd.setCursor(4,0);// lcd.print(h + ":" + m + ":" + s);
//Serial.println(h + ":" + m + ":" + s);// IMPRIMO HORA,:,MINUTO, :,SEGUNDO
// lcd.setCursor(1,1);// lcd.print(String(days[dayOfWeek]) + " " + d + "/" + mth + "/20" + year);
Serial.println(String(days[dayOfWeek]) + " " + d + "/" + mth + "/20" + year+" "+h + ":" + m + ":" + s);// IMPRIMO DIA,MES,AÑO
delay(1000); // Esperamos un segundo
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
espero que sirva
saludos