I2C BUS mit dem Uhrenbausteil DS1307

Ich habe mit von Ebay eine fertige Plantine mit Batterie und dem Uhrenbaustein DS1307 besorgt. Angestuerert habe ich die Uhr mit einen ATMEGA8 Controller über den I2C Bus. Auch Habe ich das Uhrenmodul mit meinen Arduino UNO angesteruet.

Arduino Sketch

#include <SoftwareSerial.h>
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68                          // I2C Adresse
 
char buffer[20] = "";                                    // Speicherbereich für Datenkonvertierung 
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; 
int led =13;
int command = 0;  
char  *Day[] = {"","Sontag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"};
char  *Mon[] = {"","Januar","Febuar","Maerz","April","May","Juni","Juli","August","September","Oktober","November","Dezember"};
 
 
 
 
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}
 
 
 
 
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}



 
/****************************************************************************************************
* Zeit und Datum aus DS1307 auslesen und konvertieren
*/
void getDateDs1307()
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);         // I2C-Kommunikation im Schreibmodus starten
  Wire.write(0x00);                                    // Registerzeiger auf 0 setzen
  Wire.endTransmission();                             // I2C-Kommunikation beenden 
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);            // I2C-Kommunikation im Lesemodus starten
 
  second     = bcdToDec(Wire.read() & 0x7f);
  minute     = bcdToDec(Wire.read());
  hour       = bcdToDec(Wire.read());  // Need to change this if 12 hour am/pm& 0x3f
  dayOfWeek  = bcdToDec(Wire.read());
  dayOfMonth = bcdToDec(Wire.read());
  month      = bcdToDec(Wire.read());
  year       = bcdToDec(Wire.read());
  
  Serial.print("Heute ist ");
  Serial.print(Day[dayOfWeek]);
  Serial.print(" der ");
  Serial.print(dayOfMonth, DEC);
  Serial.print(" ");
  Serial.print(Mon[month]);
  Serial.print(" ");
  Serial.print("20");
  if (year < 10)
    Serial.print("0");
  Serial.print(year, DEC);
  Serial.print(" ");
  if (hour < 10)
    Serial.print("0");
  Serial.print(hour, DEC);
  Serial.print(":");
  if (minute <10)
   Serial.print("0");
  Serial.print(minute,DEC);
  Serial.print(":");
  if (second <10)
    Serial.print("0");
  Serial.print(second,DEC);
  Serial.print(" Uhr");
  Serial.println();
}





void setup()
{
  Wire.begin();
  // start serial port at 9600 bps:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  pinMode(led, OUTPUT);
 
 /* Auskomentiert Uhr Stellen
  second=0x00;
  minute=0x39;
  hour=0x16;
  dayOfWeek=0x01;
  dayOfMonth=0x04;
  month=0x08;
  year=0x0D;
   Wire.beginTransmission(DS1307_I2C_ADDRESS);
   Wire.write(0x00);
   Wire.write(second);    // 0 to bit 7 starts the clock
   Wire.write(minute);
   Wire.write(hour);      // If you want 12 hour am/pm you need to set
                                   // bit 6 (also need to change readDateDs1307)
   Wire.write(dayOfWeek);
   Wire.write(dayOfMonth);
   Wire.write(month);
   Wire.write(year);
   Wire.endTransmission();
Auskomentieren uhr stellen ende!! */


}




void loop()
{
  // if we get a valid byte, read analog ins:
  if (Serial.available() > 0) {
    Serial.println("hallo was willst du den?");              
  }

  
  getDateDs1307(); 
  

 
  digitalWrite(led, HIGH);
  delay(200);
  digitalWrite(led, LOW);
  delay(790);
}