Bestill my beating silicon heart

Ok, here is a neat C function for converting BCD to Binary:

uint16_t bcdtoi(uint16_t bcd_number)
{
uint16_t integer;

integer = ((bcd_number&0x000F) >> 0) * 1;
integer += ((bcd_number&0x00F0) >> 4) * 10;
integer += ((bcd_number&0x0F00) >> 8) * 100;
integer += ((bcd_number&0xF000) >> 12) * 1000;

return integer;
}
If you only want to deal with 8 bit numbers then feed in 8 bit variables and comment out the last two lines inside the body.

I have used this with the AVR Mega32 to ead in input from a DS1307

Comments