Go Down

Topic: i2c and a Dallas RTC Anyone?? (Read 3 times) previous topic - next topic

Gonzillaaa

yep, that's done the trick. One final thing if I'm setting the hour to be 6, how do I know if its am or pm? or how can I set it to be 18:00 instead of 6?

Many thanks,

bluesterror

#16
Jul 02, 2007, 08:16 pm Last Edit: Jul 02, 2007, 08:17 pm by bluesterror Reason: 1
Quote
yep, that's done the trick. One final thing if I'm setting the hour to be 6, how do I know if its am or pm? or how can I set it to be 18:00 instead of 6?


That's what the high bits of the hour are for.  From the datasheet, you have in the top nibble: bit 2 selects 12 or 24 hour time, bit 1 is either the am/pm indicator or the high bit of the 24 hour time.

So use (0x40 | your_time) for 24-hour, or ( ((is_am) ? 0 : 0x02) | your_time) for am/pm mode.

libhart

I also thought about getting this to drive a clock and be very hands off, and for me that means adjusting for DST so once set I shouldn't have to touch it.  I've written code that barely fits into an ATMEGA8 that adjusts automatically for DST in the US...granted that you can't set the time w/the code, the 1307 has to already have your standard time in it, but it's pretty neat I think nonetheless.  Of course you could just use a in input and flip a switch to tell the arduino to adjust or not, but this is all in software and automagic.

bluesterror

Quote

So use (0x40 | your_time) for 24-hour, or ( ((is_am) ? 0 : 0x02) | your_time) for am/pm mode.


This is some really bad advice btw.  I need to go back to bit shifting school.

24 hour mode: just use your_hour with no ORs (bit 6 - 0=24 hr, 1=12 hr)
12 hour mode: use -
   0x40 | ((is_am) ?  0 : 0x20) | your_hour

your_hour should be binary-coded decimal (so 0x13 == 1pm in 24 hour mode).

bluesterror

Quote
I also thought about getting this to drive a clock and be very hands off, and for me that means adjusting for DST so once set I shouldn't have to touch it.


Nice!

Go Up