Arduino Duemilanvove RTC Modul 20x4LCD

Dbilas 2011-10-11 23:12:38 Link
Ich habe ein Problem mit dem RTC Modul von Watterott. Wenn keine Spannung
an dem Modul anliegt dann gibt es mir Überall 0 aus und als Jahr 200. Wenn
ich Spannung anlege dann ändert sich die Ausgabe der Zeit nicht (noch immer
0:0:00). Als Datum steht dann Sun /1/1/200.

Ich habe schon andere Codes mit Serieller Ausgabe probiert doch leider
bekomme ich da auch keine Ausgabe bzw. Uhrzeit und Datum nicht gestellt.
Das (// setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month,
year);) wurde zu setzen der Zeit auskommentiert.

Das RTC wird über (int analogplus = 17;
int analogminus = 16;) versorgt.

Wo könnte da der Fehler liegen?


#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68
#include <LiquidCrystal.h> 
int analogplus = 17;
int analogminus = 16;


LiquidCrystal lcd(8, 9, 10, 11, 12, 13);



byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}

byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour,  // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.send(0x10); // sends 0x10 (hex) 00010000 (binary) to control register
- turns on square wave
Wire.endTransmission();
}
// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());

*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour
am/pm
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
void setup()
{
  pinMode (analogplus, OUTPUT);
    pinMode (analogminus, OUTPUT);
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
Serial.begin(9600);
// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.
second = 0;
minute = 23;
hour = 23;
dayOfWeek = 4;
dayOfMonth = 19;
month = 9;
year = 11;
// setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
lcd.begin(20, 4); // tells Arduino the LCD dimensions
lcd.setCursor(2,0);
lcd.print("RTC"); // print text and move cursor to start of next line
lcd.setCursor(4,2);
lcd.print("RTC");
delay(5000);
lcd.clear(); // clear LCD screen
}
void loop()
{
  digitalWrite (analogplus, HIGH);
  digitalWrite (analogminus, LOW);
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
&year);
lcd.clear(); // clear LCD screen
lcd.setCursor(12,0);
lcd.print(" ");
lcd.print(hour, DEC);
lcd.print(":");
if (minute<10)
{
lcd.print("0");
}
lcd.print(minute, DEC);
lcd.print(":");
if (second<10)
{
lcd.print("0");
}
lcd.print(second, DEC);
lcd.setCursor(11,1);
lcd.print(" ");
switch(dayOfWeek){
case 1:
lcd.print("Sun");
break;
case 2:
lcd.print("Mon");
break;
case 3:
lcd.print("Tue");
break;
case 4:
lcd.print("Wed");
break;
case 5:
lcd.print("Thu");
break;
case 6:
lcd.print("Fri");
break;
case 7:
lcd.print("Sat");
break;
}
lcd.print(" ");
lcd.print(dayOfMonth, DEC);
lcd.print("/");
lcd.print(month, DEC);
lcd.print("/20");
lcd.print(year, DEC);
delay(1000);
}

Andreas Watterott 2011-10-13 13:06:39 Link
Wie ist alles verdrahtet, speziell SDA und SCL?

Eine Lib für den DS1307 gibt es hier https://github.com/adafruit/RTClib

Reply

Name
eMail (not visible)
Subject (no text only in upper case; no HELP, URGENT...)
Text
HTML tags are not supported and links are generated automatically if they start with http or ftp.
Please submit long source code or log files as attachment (only registered users).
Please enter the number 8333