Never Cut & Paste without first knowing what it is you're doing, otherwise I'll be tempted to put up some code so your PIC will email me the passwords to your Bank Account.
Let's do this real slow step by step...
Look at the HOURS Register... and the first line of code...
the 'x' bits we're not interested in, the other bits we are... I've named them from a (Bit 0) through to f (Bit 5). Notice after the >>4 where we shift everything four places to the right we're left with the bits that were in positions 4 thru 7 shifted into positions 0 thru 3, the bits that previously occupied 0-3 have been shifted into oblivion and with zero's shifted into the upper four bits (positions 4-7).Code:Bit 7 6 5 4 3 2 1 0 x x f e d c b a = RTCHour 0 0 0 0 x x f e = DecimalHour after >>4 rotation
The next stage is we AND it with $03... this is because we're only interested in the bits located at 0 and 1, and those two x's could be crap we don't want...
We then multiply the resultant by ten (since it's the TENS digit, and we finally add in the lower four bits of RTCHour ... and that just to clarify visually what ANDing with $0F accomplishes...Code:Bit 7 6 5 4 3 2 1 0 0 0 0 0 x x f e = DecimalHour 0 0 0 0 0 0 1 1 = AND'd with $03 0 0 0 0 0 0 f e = Result after AND operation
NOW, when you're dealing with MINUTES (see your Datasheet Register for MINUTES) you will notice we have bits 0 thru 6 which are significant (not bits 0 thru 5 as with the HOUR). So if you use $03, you will be happy ONLY if you have 00-39 minutes (because bit 6 of the TENS DIGIT is never extracted - it's masked out - therefore minutes 40-59 won't work)... so instead of $03 you need to do $07 as follows...Code:Bit 7 6 5 4 3 2 1 0 x x f e d c b a = RTCHour 0 0 0 0 1 1 1 1 = AND'd with $0F 0 0 0 0 d c b a = Result after AND operation (the enitire UNITS DIGIT of the BCD RTCHour Register)
Only then you can multiply it by ten (since it's the TENS DIGIT) and add-in the units as previously.Code:Bit 7 6 5 4 3 2 1 0 x g f e d c b a = RTCMinute 0 0 0 0 x g f e = DecimalMinute after >>4 rotation 0 0 0 0 0 1 1 1 = AND'd with $07 0 0 0 0 0 g f e = DecimalMinute AFTER ANDing with $07
Clear as mud I trust?
Bookmarks