Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to switch between 12/24 hour format RTC DS1307

Status
Not open for further replies.

4S7thilak

Junior Member level 1
Junior Member level 1
Joined
Apr 20, 2010
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,398
I too is one who has found this difficult. But when I see this forum it looks like some one showing the color of milk to blind. Why not give the details from start to the end without giving so many problems, rather than trying to be smart and wise.
 

Well....If you have read DS1307 data sheet then you may get the idea how to set time. its simple, just go through the datasheet you will know.
 

The DS1307 can be run in either 12-hour or 24-hour mode. Bit 6 of the hours register is defined as the 12-hour or 24-hour mode-select bit. When high, the 12-hour mode is selected. In the 12-hour mode, bit 5 is the AM/PM bit with logic high being PM. In the 24-hour mode, bit 5 is the second 10-hour bit (20 to 23 hours). The hours value must be re-entered whenever the 12/24-hour mode bit is changed.
 

I've read the data sheet several times but did'nt get the idea how to write to the registers....
 

Hobbyckts gave you the answer in post #3.
BTW, that information is at the datasheet.
 

Hi,

this has been discussed several times in this forum.

See the links in the box "similar threads"

Klaus
 

may have. but no one properly explains how to do it from the beginning to the end and to where etc.,
 

I use mikroC for pic, still they in their example even, have not explained. . .
 

Hi,

Just reading the datasheet tells you all.

And in at least one other thread i explained it more detailed.
All my knowledge how to change clock setting is from the datasheet.

Klaus
 

Reference: , Section: CLOCK AND CALENDAR, Page: 8

The DS1307 can be run in either 12-hour or 24-hour mode. Bit 6 of the hours register is defined as the 12-hour or
24-hour mode-select bit. When high, the 12-hour mode is selected. In the 12-hour mode, bit 5 is the AM/PM bit with
logic high being PM. In the 24-hour mode, bit 5 is the second 10-hour bit (20 to 23 hours).

The hours value must be re-entered whenever the 12/24-hour mode bit is changed.


DS1307.JPG


Please post or upload a zip file of your code, so that it maybe reviewed and additional assistance offered.


BigDog
 

he never have given the solution. . .

- - - Updated - - -

every one shows the data sheet. but no one ever shows where, when and how to do this. . .

- - - Updated - - -

if you visit many sites this could be found. the above data sheet shows the chart. but dont know the code to write.
 
Last edited by a moderator:

Seems you don't want to work on anything & you just need the readily available code. If that is the try to Google it.
 

Hoped this help

Code:
I2C1_Init(100000)     ' initialize full master mode
   I2C1_Start()          ' issue start signal
   I2C1_Wr(0xD0)         ' address DS1307
   I2C1_Wr(0)            ' start from word at address (REG0)
   I2C1_Wr(0x80)         ' write $80 to REG0. (pause counter + 0 sec)
   I2C1_Wr(0x58)         ' write 0 to minutes word to (REG1)
  [B][COLOR=#ff0000] 'I2C1_Wr(0x51)        ' write 11 AM to hours word (12-hours mode)(REG2)  
             ' by setting bit6 of timekeeping register
   'I2C1_Wr(0x71)        ' write 11 PM to hours word (12-hours mode)(REG2)
             ' by setting bit6 and bit5 of timekeeping register
   I2C1_Wr(0x11)         ' write 11 to hours word (24-hours mode)(REG2)[/COLOR][/B]
   I2C1_Wr(0x07)         ' write 7 - Saturday (REG3)
   I2C1_Wr(0x24)         ' write 4 to date word (REG4)
   I2C1_Wr(0x10)         ' write 10 (October) to month word (REG5)
   I2C1_Wr(0x09)         ' write 09 to year word (REG6)
   I2C1_Stop()           ' issue stop signal
 
Thank you so much. This was the one I was and others looked for ...It is working.
 

Thank you so much. This was the one I was and others looked for ...It is working.

All of expert of this forum replied to your thread, to do it yourself while giving most important info but you should not captured them, please try to do rest yourself by respecting to them and post any issues they will help you
 

Hi

Thank you so much. This was the one I was and others looked for ...It is working.
Hints for your future:
* if you want code: then you first should show what you have done so far.
* if you want code, then you should say so. But you used the word code the first tim in post #11
* if you want code, then you need to say what hardware you use (microcontroller type) and what software you use (compiler). But you mentioned "pic"and "microC" only in post#8

And be polite to the people who wants to help you. Everybody who answers you invests time into your problem without the chance of gaining a reward. Show them that you worked hard to find a solution for yourself. Show them what you did so far...

Klaus
 

Dear friend, I still struggling to get over the problem of changing between 12/24 hour modes. I did all the codes you said, nothing happens. It goes only on 24 hr mode. Can you please show the particular register and how to address to. I know its like . eg. PORTB.b6=1 is bit 6 of the PORTB is high. but there is no such possibility for this. When you write to HOUR register eg. write_ds1307(2,0x40), it connects to the time and NOT the mode. tnx.

- - - Updated - - -

Thanks. Sorry if I have hurt anybody's feelings. I was and still in the same boat without any proper solution.
 

Hi,

we tried to help you as much as we can.

But it´s on you to give us informations:

I did all the codes you said, nothing happens.
This tells nothing what you really did, what you epected and what happened instead. Its useless for us to help you.

so please:
* post your code (with included remarks/documentation)
* tell us what you want to achieve
* and give us detailed information what happens instead.


***
write_ds1307(2,0x40)
This sets bit 6 of hour register (Addr2), and for sure clears the other 7 bits.
result is:
* 12 h mode (bit 6)
* AM (bit 5)
* 0 for 10 hours (bit4)
* 0 for unit hours (bits 3:0)

added:
--> 12h mode, 0:00 AM

Klaus
 
Last edited:

Dear friend, I still struggling to get over the problem of changing between 12/24 hour modes.

I have to admit that I'm unable to explain in other words differently from what was already said before.

Anyway, in order to solve the problem, why don´t you consider keep storing the time in 24 hs, but making the proper conversion by a simple code before displaying on LCD ?
 

Please post your code
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top