DS1302 Timekeeper-Using Modulus Operator With BCD
Mikerocontroller
Posts: 310
· I'm using the DS1302 timekeeper chip and would like to detect when the minutes = 15, 30, and 45.
I tried:
·IF minutes//15=0 THEN Do_Something
· This doesen't work with binary coded decimal.· What formula can I use?
I tried:
·IF minutes//15=0 THEN Do_Something
· This doesen't work with binary coded decimal.· What formula can I use?
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 1/1/2010 5:34:13 AM GMT
By the way, Happy new year!
IF minutes.nib1*10+minutes.nib0//15=0 THEN Do_Something
That is true also when minutes=0, which was not in your list. Another conditional needed?
On the subject of BCD and the modulus // operation. Here is a little mathematical quirk. If minutes is in BCD form, it is obvious that
IF minutes//2=0 THEN Do_Something
will work, because an even number is even no matter how you convert it. It is also true
IF minutes//3=0 THEN Do_Something
and
IF minutes//6=0 THEN Do_Something
will work with minutes left in BCD form. It so happens that BCD and Decimal are congruent both mod 2 and mod 3.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
minutes VAR Byte
seconds VAR Byte
IF (minutes.HIGHNIB*10+minutes.LOWNIB//15=0) AND (seconds=0) THEN GOSUB Perform_An_Action
Of course whatever action is taken should take at least a second or the action will be performed multiple times as long as (seconds=0)
··· Sorry Tracy I did'nt know you posted........................................
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com