Ds1307 12 hr mode settings

Status
Not open for further replies.

Dumken

Member
Hi.. good day guys. Can someone pls help me with a code to set ds1307 to operate in the 12 hr mode instead of 24hrs mode.(mikroc)
 
Concentrate purely on register 3... When you write you need to set the AM / PM flag and also set the 24 / 12 flag


Assume 16:00.. If you want it to be 12 hour clock you write 0x64 instead of 0x16..


AMPM = 0x40

If hour> 12
AMPM += 0x20
hour -= 12
hour = ((hour / 10) << 4) + (hour % 10)
hour = hour + AMPM
 
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.
 
koolguy thanks for ur idea. Ian thank u very much but can u break the code down.. the 12 is it in decimal or hex?
 
Decimal... Noon... Midnight!! 12 oclock!!!

You still convert to BCD ( that's what the second bit does!!)
 
pls forgive my too much questions.. i tried it but its not working. do i have to write to it after the manipulation
 
MikroC has the routines BCD-BIN and visa versa..

When you read the DS1307 do you keep it in BCD??? If so the job is a tad easier!! When you write to the DS1307

Just add 4 to the high nibble if the clock is AM, and add 6 if it is PM..

In BCD 4:00 PM will be 64 hex 24 PM,0,4
4:00 AM will be 44 hex 24,AM,0,4
11:00 AM will be 51 hex 24,AM,1,1
11:00 PM will be 71 hex 24,PM,1,1​
 
Excuse me guys. Everything seems to be working well just that at "12am" i am seeing "00" in my segment

This is
Code:
void am2pm()
{
      hour = Bcd2Dec(hour);
      if (hour > 12)
      {
      AMPM = 0x60;
      hour -= 12;
      }
      else
      {
       AMPM = 0x40;
      }
      hour = Dec2Bcd(hour);
      hour = hour + AMPM;

}
the code i used. Any error noticed??
 
Should work, However!!

change this.... hour = Bcd2Dec(hour); to hour = Bcd2Dec(hour) & 0x1f;

Or it will pickup on the PM and will show faulty readings..

C:
void am2pm()
{
      hour = Bcd2Dec(hour) & 0x1F;
      if (hour > 12)
      {
      AMPM = 0x60;
      hour -= 12;
      }
      else
      {
       AMPM = 0x40;
      }
      hour = Dec2Bcd(hour);
      hour = hour + AMPM;

}
 
That is wat am getting when it gets to the 24th hr which is meant to be 12am in 12hr mode and 00 in 24hr mode
 

Attachments

  • Clock code.bmp
    915.8 KB · Views: 291
i know its correct. But cant i get sometyn like 12am with the code?
And again i noticed that the code is not obeying the conditional statement. Ian if i may ask have u worked with that code before?
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…