So, I've been banging my head against the wall for the past couple days on this. I can get everything to work (mega2560 R3, 16x02 LCD, DS1307 rtc) and the first time I uploaded the henning karlson sketch, it worked perfectly. So, happy I managed to get something accomplished, I unplugged the arduino and set it aside for a day. Came back 2 days later, and the date was 3 months ahead. No clue how that happened. So, figuring some of my jumpers got knocked loose, or something silly, I rewired the whole setup on my breadboard. Now for the life of me I cannot get the day to display correctly on the LCD. I can change the time, month, and year no problem, but heck if the day will change. Which I find extremely odd. Especially considering all I changed within the sketch were the pins used, and the date/time.
Am I missing something stupidly simple? Or could this be due to a hardware issue? Any help will be appreciated.
Here's the sketch I have so far:
// DS1307_LCD (C)2010 Henning Karlsen
// web: Electronics - Henning Karlsen
//
// A quick demo of how to use my DS1307-library to make a quick
// clock using a DS1307 and a 16x2 LCD.
//
// I assume you know how to connect the DS1307 and LCD.
// DS1307: SDA pin -> SDA 20
// SCL pin -> SCL 21
// LCD: DB7 -> Arduino Digital 50
// DB6 -> Arduino Digital 48
// DB5 -> Arduino Digital 46
// DB4 -> Arduino Digital 44
// E -> Arduino Digital 42
// RS -> Arduino Digital 40#include <LiquidCrystal.h>
#include <DS1307.h>// Init the DS1307
DS1307 rtc(20, 21);// Init the LCD
LiquidCrystal lcd(40, 42, 44, 46, 48, 50);void setup()
{
// Set the clock to run-mode
rtc.halt(false);// Setup LCD to 16x2 characters
lcd.begin(16, 2);// The following lines can be commented out to use the values already stored in the DS1307
rtc.setDOW(THURSDAY); // Set Day-of-Week
rtc.setTime(1, 50, 30); // Set the time
rtc.setDate(04, 18, 2013); // Set the date// Set SQW/Out rate to 1Hz, and enable SQW
rtc.setSQWRate(SQW_RATE_1);
rtc.enableSQW(true);
}void loop()
{
// Display time centered on the upper line
lcd.setCursor(4, 0);
lcd.print(rtc.getTimeStr());// Display abbreviated Day-of-Week in the lower left corner
lcd.setCursor(0, 1);
lcd.print(rtc.getDOWStr(FORMAT_SHORT));// Display date in the lower right corner
lcd.setCursor(6, 1);
lcd.print(rtc.getDateStr());// Wait one second before repeating
delay (1000);
}