View previous topic :: View next topic |
Author |
Message |
glk.c.93
Joined: 27 Jun 2012 Posts: 9 Location: India
|
Enable 12 hr format of DS1307 using PIC16f887A |
Posted: Wed Jun 27, 2012 7:26 am |
|
|
hi....
I am trying to enable 12 hour format in DS1307 using 16f877A.
I have a few doubts...!
When should we enable the 7th bit for 12 hour format.
1)During writing of hour (ex: for 3AM as 3 | 0b01000000) into RTC or
2)during initialization
If we activate 12 hour format then RTC goes automatically from 12:59:59Pm to 01:00:00Pm...r8?
During activation of 12 hour format... should I need to define the 5th bit too (for PM / AM as 1/0 respectively)?
Is there any need of using FORCE_HW, FORCE_SW in use_i2c() ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed Jun 27, 2012 8:36 am |
|
|
1) yes, that should work....
2) no, see above...
3) yes.
4) yes. if you don't then the RTC will NOT be in sync with Mother Nature ! You could be off by 12 hours!
5) if you force hardware, the code will use the internal I2C pins, forcing software allows you to use any 2 I/O pins, within design limits.
It's always best to consult the DS1307 datasheet, as it will give advice about proper setup of function versus registers.
hth
jay |
|
|
glk.c.93
Joined: 27 Jun 2012 Posts: 9 Location: India
|
re: |
Posted: Wed Jun 27, 2012 9:01 am |
|
|
I tried to intialize 12 hr format as 12|0b01100000 for 12 pm......
I am trying to display it on a screen taking only five bits into consideration as
hr=hr&0x1f.
later after 12:59:59 iam getting 13:00:00 and not 1:00:00
& it hasn't seem to change 5th bit as one after 11:59:59AM (i.e it seems that 12 hour mode is not activated).
any help? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed Jun 27, 2012 10:03 am |
|
|
According to the DS1307 datasheet , "...
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. ..."
So it says you must reenter the hours values after you've changed to 12 or 24 hr modes.
I'm not near my PIC PC so I can't try it, but perhaps you can alter your 'set time' code and see what happens.
I'm a '24hr' guy, saves a LOT of confusion....
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19550
|
|
Posted: Wed Jun 27, 2012 1:38 pm |
|
|
Big problem is that the time your are putting is is impossible in 12hr mode. 11:59:59, is the highest number that can be entered. It then jumps to 00:00:00.....
Best Wishes |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Jun 27, 2012 3:06 pm |
|
|
Quote: | I'm a '24hr' guy, saves a LOT of confusion.... |
Could not agree more. Decades ago I had a problem with a client over whether 12:30 on a 24 hr clock was am or pm on a 12 hr clock. Going to 24hr solved it.
Mike |
|
|
glk.c.93
Joined: 27 Jun 2012 Posts: 9 Location: India
|
|
Posted: Wed Jun 27, 2012 10:09 pm |
|
|
Ttelmah wrote: | Big problem is that the time your are putting is is impossible in 12hr mode. 11:59:59, is the highest number that can be entered. It then jumps to 00:00:00.....
Best Wishes |
Thanx for reply.............
but
11:59:59 isn't the highest
12:59:59 is highest in 12 hr format
http://en.wikipedia.org/wiki/12-hour_clock
00:00:00 occurs only in 24 hr format clock not in 12 hr format. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19550
|
|
Posted: Thu Jun 28, 2012 1:12 am |
|
|
Not for that chip.....
Have had exactly this problem some years ago. If you try to write a value over 11:59, to this chip in 12 hour mode, it switches to 24 hour mode.
Best Wishes |
|
|
glk.c.93
Joined: 27 Jun 2012 Posts: 9 Location: India
|
re: |
Posted: Thu Jun 28, 2012 1:19 am |
|
|
In this case how should i activate the 12 hr mode.......
what time can i give for 12hr mode? |
|
|
glk.c.93
Joined: 27 Jun 2012 Posts: 9 Location: India
|
Its working |
Posted: Thu Jun 28, 2012 1:32 am |
|
|
Its working
if we give 12:59:59 it will change to 1:00:00
but you should activate the 12 hr clock by giving 0x72 not bin2bcd(12|0b01100000).
Because in bin2bcd() the number transforms into another number. |
|
|
nisha
Joined: 09 Nov 2011 Posts: 6 Location: mumbai
|
|
Posted: Sat Oct 20, 2012 5:51 am |
|
|
i m using ds1307 interfaced with pic16f877a, my code is working but the problem is, if i m continuously keeping it on, the time goes on reducing. say after 5 min it will decrease by 1 sec, will may create a problem after some hour...
plz help me.. _________________ Nisha Yetiwar |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Oct 20, 2012 6:21 am |
|
|
Nisha,
Your problem is not the same as discussed in this topic. For a new problem always start a new thread, that makes it easier for other people to search for similar problems.
If you still have problems, then start a new thread. |
|
|
|