How to switch between 12/24 hour format RTC DS1307

Status
Not open for further replies.

Just like this ?

hour = BCD2Binary(hour);
hour = hour + set;
hour = Binary2BCD(hour);
hour = hour + 0x40; (0x40 = 0b01000000 6th bit high)
write_ds1307(2, hour);

?
 

I think it will work? In this write_ds1307(2, hour); what is 2? Is the hour register, register no. 2 in ds1307?

thats not working ... i made it very simple

if(d1==0)d1+=12;
else if(d1>=13)d1-=12;

if i put this condition true... its 12 hour mode and if not then its 24 hour mode my problem is solve by simple arithmetic.

Actually i tried XOR and Addition of 0b01000000 but i was getting some other values on display. So i finally decide to make it simple by using above code. Thanks mate for your help.
 

I refer that only but I m not able to get the code working. That code works well in lcd but when converted to decimal value is some kind kind of different.

- - - Updated - - -

I want to make this condition
f(d1==0)d1+=12;
else if(d1>=13)d1-=12;

true and false based on port pin7 switch.. Please suggest me how to do it I tried but not success

- - - Updated - - -

So when I click switch it would be in 12 hour mode and click again to get back 24 mode.



I mean to say simple toggle switch
 

Post you full code with Proteus file. (zip and post) Does your pin to which switch is connected becomes low on pressing the switch? Do you just want the button code?

Hello,

16F72 is not available in proteus simulation. My input pins are pulled-up to +5V using 10K Resistor. when i push button they're are grounded. Means when i push its 0 and in normal state its 1. Just gimme the code to toggle any variable with 0 and 1 so i can switch between 12/24 hour format.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…