Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Expalanation Needed about this code

Status
Not open for further replies.
Advanced Member level 4
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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top