one button ds-1307 syncronization

Berny

Member
In the thread "Daily Lights" there is mentioned a one button synchronization to set the ds-1307. Could you point me to the circuit diagram and code for this please?
 

Berny

Member
Thanks hippy, you are correct, that was the thread. I also seem to remember a thread where someone built a clock that could be set with buttons but cannot seem to find it now. I have the ds-1307 displaying the time but cannot get it in sync with the correct time. Any suggestions would be appreciated.
 

bryanl

Member
What I have is a button to set seconds to the nearest minute:

Code:
; set seconds to 0 and round off minutes to nearest
; but ignore if minutes will exceed 0-59 to avoid calendar rollovers
Symbol ij = w20		; loop and counter indices
Symbol i = b40		; and other temporary values
Symbol j = b41		; of short life in routines
Symbol kl = w21
Symbol k = b42
Symbol l = b43
zero_seconds:
	hi2cin 0,(i,j)		; get clock seconds and minutes
	k = BCDtoBIN i
	l = BCDtoBIN j
	If k > 29 AND l < 59 Then
		i = 0
		inc l
		j = BINtoBCD l
		hi2cout 0,(i, j)		; update clock
	Else if K < 30 Then	; round down, no minute adjust
		i = 0
		hi2cout 0,(i)
	EndIf
Return
setting the clock can get rather complicated. Even with something this simple, the case of a date change is ignored so don't set zero seconds at midnight! This code avoids this by ignoring efforts that might cause hours rollover.

Trying to keep the calendar consistent on any clock change can be significant challenge. This means that changes between local and UTC, for instance, need to either avoid or accommodate calendar rollovers for day, month, and year and that means either using the internal calendar in the clock chip or employing your own calendar knowledge complete with days in month and leap year concerns.
 

Berny

Member
Going to have to study this to get the idea. Getting confused with the BCDtoBIN and then checking ASCII numbers
l = BCDtoBIN j
If k > 29 AND l < 59 Then
Thanks Bryanl for the reply and the code. Now, where would the button go in the circuit? Sorry, not very good at this yet. In fact, now have a more pressing issue of getting a countdown timer to work
I am going to start a new thread :(
 

bryanl

Member
Manual 3 page 26 has the rundown on switch circuit and code example. There should be plenty of examples around here you can use as well. Also check manual 2 p27 on Input / Output Naming Conventions. All the switch does is to control the logic level on an input pin.

The clock chip keeps its time values as 2 BCD values in an 8 bit byte. That means the bottom 4 bits (called a nibble) is a number from 0 to 9 and the top four bits has another number from 0-9. The top nibble and the bottom nibble are separate entities that are supposed to be kept independent if they are going to be properly used as a BCD coded number. The BCDtoBIN function will parse out the two numbers from the nibbles and put them together to make an integer (8 bit) value going from 0 to 99 decimal. The BINtoBCD will take an integer, split out the decimal tens digit and the decimal units digit and then create a BCD coded byte.

Note that you aren't using ASCII! That's another encoding system of its own. You get into that can of worms when you try to put something that makes sense on a display panel.
 
Top