Hi There,
I bought a DS1302 (see here : Recommendations For You - DealeXtreme ).
I use this piece of code : Arduino Playground - DS1302 (or also a library from here : arduino-ds1302/DS1302.h at master · msparks/arduino-ds1302 · GitHub).
However, I am getting wierd result.
The time I see is not one the one I read afterwards.
When setting time for exemple, it affects the date...
Here below my sketch.
Anyone has ideas?
I get this as output : "08:17:09 21.09.2001 Sun" whereas my code sets : rtc.setDOW(SATURDAY); rtc.setTime(16, 1, 3); rtc.setDate(7, 9, 13);
Thanks,
Erwan
// DS1302_LCD (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// A quick demo of how to use my DS1302-library to make a quick
// clock using a DS1302 and a 16x2 LCD.
//
// I assume you know how to connect the DS1302 and LCD.
// DS1302: CE pin -> Arduino Digital 12
// I/O pin -> Arduino Digital 11
// SCLK pin -> Arduino Digital 10
// LCD: DB7 -> Arduino Digital 7
// DB6 -> Arduino Digital 6
// DB5 -> Arduino Digital 5
// DB4 -> Arduino Digital 4
// E -> Arduino Digital 8
// RS -> Arduino Digital 9
#include <LiquidCrystal.h>
#include <DS1302.h>
// Init the DS1302
//DS1302(ce, data, clock);
DS1302 rtc(12,11,10);
// Init the LCD
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );
void set_time() {
rtc.setDOW(SATURDAY); //
rtc.setTime(16, 1, 3); //
rtc.setDate(7, 9, 13); //
}
void setup()
{
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);
//rtc.setTCR(TCR_OFF);
// Setup LCD to 16x2 characters
lcd.begin(16, 2);
set_time();
// The following lines can be commented out to use the values already stored in the DS1302
}
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);
}
DS1302.h (3.22 KB)
DS1302.cpp (9.94 KB)
DS1302.pdf (55.9 KB)