Just for the sheer hell of it, here's a stab (I haven't run it so you'll probably have some debugging to do)
typedef struct plainDT
{int year;
int month;
int day;
int hour;
int minute;
int second;
};
plainDT targetDate={2017, 12, 25, 0, 0, 0}; //Christmas day 2017
plainDT diff;
char diffString[21];
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
RTC_DS1307 RTC;
void setup () {
Serial.begin(9600);
Wire.begin();
RTC.begin();
lcd.begin(20, 4);
pinMode(8,OUTPUT);
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop () {
DateTime now = RTC.now();
lcd.setCursor(0, 0);
lcd.print("Digital Clock");
lcd.setCursor(0, 1);
lcd.print(now.day(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.year(), DEC);
lcd.print(' ');
lcd.setCursor(0, 2);
if (now.hour()<10)
lcd.print('0');
lcd.print(now.hour(), DEC);
lcd.print(':');
if (now.minute()<10)
lcd.print('0');
lcd.print(now.minute(), DEC);
lcd.print(':');
if (now.second()<10)
lcd.print('0');
lcd.print(now.second(), DEC);
lcd.setCursor(0, 3);
int dayofweek = now.dayOfWeek();
switch(dayofweek){
case 1:
lcd.print("Monday");
break;
case 2:
lcd.print("Tuesday");
break;
case 3:
lcd.print("Wednesday");
break;
case 4:
lcd.print("Thursday");
break;
case 5:
lcd.print("Friday");
break;
case 6:
lcd.print("Saturday");
break;
case 0:
lcd.print("Sunday");
break;
}
calculate();
lcd.setCursor(0,0);
lcd.print(diffString);
delay(1000);
}
void calculate()
{
DateTime now=RTC.now();
plainDT TARGET=targetDate;
plainDT NOW={now.year(),now.month(),now.day(),now.hour(),now.minute(),now.second()};
//makes maths easier if months are zero based
TARGET.month--;
NOW.month --;
int maxDays[]={31,28,31,30,31,30,31,31,30,31,30,31};
int dayCount=maxDays[NOW.month];
if ( (NOW.month==1) && NOW.year==( (NOW.year/4) * 4) )
dayCount=29;//works for any year within the next 3 centuries at least
diff.second = TARGET.second - NOW.second;
if (diff.second < 0)
{
diff.second = 60 + diff.second;
NOW.minute++;
}
diff.minute = TARGET.minute - NOW.minute;
if (diff.minute < 0)
{
diff.minute = 60 + diff.minute;
NOW.hour++;
}
diff.hour = TARGET.hour - NOW.hour;
if (diff.hour < 0)
{
diff.hour = 24 + diff.hour;
NOW.day++;
}
diff.day = TARGET.day - NOW.day;
if (diff.day < 0)
{
diff.day = dayCount + diff.day;
NOW.month++;
}
diff.month = TARGET.month - NOW.month;
if (diff.month < 0)
{
diff.month = 12 + diff.month;
NOW.year ++;
}
diff.year = TARGET.year - NOW.year;
if (diff.year < 0)
diff=(plainDT){0,0,0,0,0,0};
sprintf(diffString,"%04d %02d %02d %02d:%02d:%02d",diff.year, diff.month, diff.day, diff.hour, diff.minute, diff.second);
}