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.
Please see mikroC PRO PIC example of RTC DS1307. You can get the examples if you install the demo version of mikroC PRO for PIC. You can also get the code from libstock.com Search for RTC DS1307. The code shows how to write data to ds1307, read ds1307.

- - - Updated - - -

Please see mikroC PRO PIC example of RTC DS1307. You can get the examples if you install the demo version of mikroC PRO for PIC. You can also get the code from libstock.com Search for RTC DS1307. The code shows how to write data to ds1307, read ds1307.

24 hr = 100100. In 24 hr mode you dont use 5th bit. 6th bit is used and is 0, so you pass bcd values 0...24. In 12 hr mode you write 5th bit and 6th bit once only. Are you asking how to pass data in this condition?

After doing dec2bcd(12) you get 10010. add 1000000 or 1100000 to it and then write the value to hour.

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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top