2-digit BCD to Decimal conversion function:
unsigned short myBcd2Dec(unsigned short bcd){
return ((bcd >> 4)*10+(bcd & 0x0F));
}
return ((bcd >> 4)*10+(bcd & 0x0F));
}
Example: myBcd2Dec(01000101) = 45
2-digit Decimal to BCD conversion function:
unsigned short myDec2Bcd(unsigned short dec){
return (((dec/10)<<4)(dec%10));
}
return (((dec/10)<<4)(dec%10));
}
Example: myDec2Bcd(45) = 01000101
3 comments:
in the code there is not mentionaned any date and time is it?
No, the code is not the full clock code. It's just the code for 2-Digit BCD to decimal conversion and vise versa. The code for the full working Clock will be posted later as I am working on it.
Useful code, it helped me check my own version of bcd conversion. But I think there is a typo (missing +) in the dec to bcd version: you shift the tens value right but should then add in the units (mod) value - not multiply.
Post a Comment