No está probado, pero sería algo como esto
#include <Wire.h> // Reloj
#include <SLCD.h> // Librería de la pantalla LCD
#define WIRE_BUS 0x68
SLCD serialLCD = SLCD( 2, 16 );
// Conversion de datos decimal a hexadecimal
byte decABcd(byte val) {
return ( (val/10*16) + (val%10) );
} // p.ej. 25 -> 37
byte bcdADec(byte val) {
return ( (val/16*10) + (val%16) );
} // p.ej. 37 -> 25
void ponReloj( byte segundo, // 0-59
byte minuto, // 0-59
byte hora, // 1-23
byte diaSem, // 1 Lunes-7 Domingo
byte dia, // 1-28/29/30/31
byte mes, // 1-12
byte anio) // 0-99
{
Wire.beginTransmission( WIRE_BUS );
Wire.send(0);
Wire.send(decABcd(segundo)); // 0 to bit 7 starts the clock
Wire.send(decABcd(minuto));
Wire.send(decABcd(hora));
Wire.send(decABcd(diaSem));
Wire.send(decABcd(dia));
Wire.send(decABcd(mes));
Wire.send(decABcd(anio));
Wire.send(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission();
}
// Toma la fecha y la hora del ds1307
void tomaHora( byte *segundo,
byte *minuto,
byte *hora,
byte *diaSem,
byte *dia,
byte *mes,
byte *anio)
{
// Resetea el registro puntero
Wire.beginTransmission( WIRE_BUS );
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom( WIRE_BUS, 7);
// Alguno de estos necesitan enmascarar porque ciertos bits son bits de control
*segundo = bcdADec(Wire.receive() & 0x7f);
*minuto = bcdADec(Wire.receive());
*hora = bcdADec(Wire.receive() & 0x3f); // Need to change this if 12 hora am/pm
*diaSem = bcdADec(Wire.receive());
*dia = bcdADec(Wire.receive());
*mes = bcdADec(Wire.receive());
*anio = bcdADec(Wire.receive());
}
void setup() {
Wire.begin();
serialLCD.init();
Serial.begin(9600);
// Si se quiere inicializar el reloj
ponReloj( 0, 0, 12, 5, 4, 4, 14 ) // 12:00 Viernes 4/4/2014
}
void loop() {
byte ss, mm, hh, dS, dd, nn, aa;
long tiempo;
tomaHora( &ss, &nn, &&hh, &dS, &dd, &mm, &aa );
Serial.print( aa, DEC );
Serial.print( "-" );
Serial.print( mm, DEC );
Serial.print( "-" );
Serial.print( dd, DEC );
Serial.print( " " );
Serial.print( &hh, DEC );
Serial.print( ":" );
Serial.println( &nn, DEC );
delay( 5000 ); // Actualiza la hora cada cinco segundos
}