Malcolm, you can't have '&$03' for MINUTES (the way you have for HOURS)... but can you figure why and what value it should be if not $03? Correct that small omission and your code will run (there's incentive for you).
Malcolm, you can't have '&$03' for MINUTES (the way you have for HOURS)... but can you figure why and what value it should be if not $03? Correct that small omission and your code will run (there's incentive for you).
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?
Mel,
Thanks for the very detailed explanation, it has helped as I wasn't sure how the $xx was related to the binary (ie 07 in binary being 111) and what exactly the >> related to.
I'll try your suggestion tonight - Thanks for the lesson, and I promise to do my homework from now on![]()
Mel, with your help I now have something I can work with
Ignore the lcdout alarmm1 etc, that was just to view the values. Interestingly it shows 19:05 as 19:5, but works regardless.Code:AlarmH1=(RTCHour>>4) AlarmH1=(AlarmH1&$03)*10 AlarmH1=AlarmH1+(RTCHour&$0F) AlarmM1=(RTCMin>>4) AlarmM1=(AlarmM1&$07)*10 AlarmM1=AlarmM1+(RTCMin&$0F) AlarmH2=(RTCHour>>4) AlarmH2=(AlarmH2&$03)*10 AlarmH2=AlarmH2+(RTCHour&$0F) AlarmM2=(RTCMin>>4) AlarmM2=(AlarmM2&$07)*10 AlarmM2=AlarmM2+(RTCMin&$0F) AlarmHour1 = 19 Alarmmin1 = 07 AlarmHour2 = 19 AlarmMin2 = 09 LCDOut ":",#(RTCMin>>4)&$0F,#RTCMin&$0F,":" LCDOut #(RTCSec>>4)&$0F,#RTCSec&$0F," " LCDOut $FE, $94,"H1M1= ",#AlarmH1,":",#AlarmM1," ",#AlarmH2,":",#AlarmM2 LCDOut $FE, $D4,"set= ",#alarmhour1,":",#alarmmin1," ",#alarmhour2,":",#AlarmMin2 If AlarmHour1=AlarmH1 and alarmmin1=AlarmM1 then HIGH PortD.7 endif if alarmhour2=AlarmH2 and AlarmMin2=alarmm2 then LOW PortD.7 endif
Thanks to everyone who contributed (both on the board and via e-mail), especially Mel for taking so much trouble to explain things in layman terms
Malc... if you want 05:05:07 rather than 5:5:7 then...
LCDOut DEC2 DecimalHours,":",DEC2 DecimalMinutes,":",DEC2 DecimalSeconds
hmmmm... DEC2 seems to be something to look up in the manual here...
Bookmarks