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.

Set 24 / 12 hour and AM / PM of RTC

Status
Not open for further replies.

PA3040

Advanced Member level 3
Advanced Member level 3
Joined
Aug 1, 2011
Messages
883
Helped
43
Reputation
88
Reaction score
43
Trophy points
1,308
Visit site
Activity points
6,936
Dear All,

My RTC DS1307 reading writing and adjustments are now working properly

The only thinks that I have to manage to set 24/12 hour and AM / PM accordingly

I mean after adjusted 24 / 12 hour and re writing to RTC not working properly

I know that bit 6 of address 0x02 of RTC should be 0 for 24 hour and 1 for 12 hour

Please advice with the logic that I have to consider in simple code

My MCU 18f452
Compiler HI TECH C lite

Please advice
 

What values are you writing to hour register and for what format, 12 hr or 24 hr?

In 24 hr mode...

0x22 gives 22 hr

0x23 gives 23 hr

0x02 gives 2 hr
 
Last edited:

In the 12 hour mode

0x51 11 AM

When I set the above value to hour register and compile the source code and program to the PIC then it is working well

But after resetting time then the new saving will effect the problem ( Adjusted time using micro switch )

please advice
 

I think you think
I2CSend(0x80); //write $80 to REG0. (pause counter + 0 sec)

I did it
 

Post your circuit. Does your RTC has a 3V battery?

No,I do not have installed the 3v battery

- - - Updated - - -

I am really asking, after resetting the time
how we set the new value for hour register without effect to the bit 6

is it necessary to OR or AND operation , then how and nay example
 

Is this the only way to toggle between 24 and 12 hour mode ?
 

Read the datasheet. The AM PM bit becomes 2nd 20 hour bit in 24 hr mode. So while toggling between modes you have to set the whole register. You can't modify just a single bit of any DS1307 register. You have to write the whole register with a new value.
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Is this correct?
1. After adjust
2.convert to BCD
3.write to new value to RTC

But in the hour
First adjust the hour
Convert to binary
AND operation with expected mode ( 24 or 12 )
then convert to the BCD
Then write to RTC

Is this correct?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top