Set 12 Hr Clock on DS1307 using RTClib

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
RossW
 
Posts: 10
Joined: Mon Dec 26, 2011 1:44 pm

Set 12 Hr Clock on DS1307 using RTClib

Post by RossW »

Hi,

I just got my adafruit ds1307 RTC board running using RTClib on an Arduino Uno R3. Is there a way to set the ds1307 to 12 hour mode using RTClib (LadyAda fork)?

Thanks!

Ross

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Set 12 Hr Clock on DS1307 using RTClib

Post by adafruit_support_bill »

Nothing specific for it in the library. But it is a fairly trivial calculation: If the hour is greater than 12, subtract 12.

RossW
 
Posts: 10
Joined: Mon Dec 26, 2011 1:44 pm

Re: Set 12 Hr Clock on DS1307 using RTClib

Post by RossW »

Thanks. That's what I've done. I was just thinking that since the data sheet raves about the ds1307 having 12/24 and am/pm clock type capabilities there might be a more elegant way to do it. I poked around on the net and found several ways to code it using other rtc libraries but none were really better than the simple calc. Oh, well.

User avatar
floresta
 
Posts: 223
Joined: Thu Jul 31, 2008 10:27 am

Re: Set 12 Hr Clock on DS1307 using RTClib

Post by floresta »

adafruit_support wrote:Nothing specific for it in the library. But it is a fairly trivial calculation: If the hour is greater than 12, subtract 12.
How do you deal with the hour following midnight? Also, you have to deal with the leading zeroes which are not normally displayed when using a 12 hour clock.

Don

odometer
 
Posts: 98
Joined: Sun Aug 21, 2011 11:01 pm

Re: Set 12 Hr Clock on DS1307 using RTClib

Post by odometer »

Look at page 8 on the data sheet.
http://datasheets.maxim-ic.com/en/ds/DS1307.pdf
But then again, I see what looks like an error in the table on that page.
I wrote to the company asking for clarification.

User avatar
floresta
 
Posts: 223
Joined: Thu Jul 31, 2008 10:27 am

Re: Set 12 Hr Clock on DS1307 using RTClib

Post by floresta »

odometer wrote:Look at page 8 on the data sheet.
http://datasheets.maxim-ic.com/en/ds/DS1307.pdf
But then again, I see what looks like an error in the table on that page.
I wrote to the company asking for clarification.
There is no question that the clock can be run in the 12 hour mode. The problem appears to be how to get it into that mode using the library. I have run my own DS1307 clocks in the 12 hour mode many times but I've never tried using the library.

I seem to remember seeing a problem with that table as well. I know that bit 6 for address 02h should be written as 12/24 in one big box but I think there was something else as well.

Don

User avatar
sdb
 
Posts: 31
Joined: Thu Jan 12, 2012 4:24 am

Re: Set 12 Hr Clock on DS1307 using RTClib

Post by sdb »

I don't think the library supports 12hr mode.

And really, why would you want it to? For all computations or comparisons 24hr mode is easier to deal with. For display you can display it however you want. It is trivial to display in 12hr when given 24hr:

Code: Select all

char ap='A';
if (hour>12) {
hour-=12;
ap='P';
} else if (!hour) {
hour=12;
}
sprintf(outstring,"%d:%02d:%02d %c.M.",hour,min,sec,ap);
If you really want the ds1307 to run in am/pm mode, just look at how the library writes to the clock and change it to write the proper value in the 12/24 bit.

Of course, you will also have to arrange to set the hour and am/pm flag bits properly as well.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”