Expalanation Needed about this code

Status
Not open for further replies.
Joined
Jul 25, 2012
Messages
1,192
Helped
171
Reputation
342
Reaction score
162
Trophy points
1,343
Visit site
Activity points
0
Hello!

I have a code for BCD to Decimal conversion of date and time

Code:
        *sec  =  ((*sec & 0x70) >> 4)*10 + (*sec & 0x0F);
        *min  =  ((*min & 0xF0) >> 4)*10 + (*min & 0x0F);
        *hr   =  ((*hr & 0x30) >> 4)*10 + (*hr & 0x0F);
        *week_day =(*week_day & 0x07);
        *day  =  ((*day & 0xF0) >> 4)*10 + (*day & 0x0F);
        *mn   =  ((*mn & 0x10) >> 4)*10 + (*mn & 0x0F);
        *year =  ((*year & 0xF0)>>4)*10+(*year & 0x0F);

sec and minutes both vary from decimal 0 to 59 and bcd 0x00 to 0x59. Then why is the formula for sec and time bcd to decimal transformation is different?

For seconds it is *sec = ((*sec & 0x70 ) >> 4)*10 + (*sec & 0x0F);

For minutes it is *min = ((*min & 0xF0 ) >> 4)*10 + (*min & 0x0F);
 

1. Don't start multiple therads on the same topic.
2. The necessity of masking out some RTC register bits (e.g. seconds.bit7) becomes obvious if you read the datasheet.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…