BCD Conversion

I found this code online and it works perfect for reading from the RTC in BCD and converting to binary to display on the LCD
Code:
void TransformTime(void)
{
    hours    =  (((hours & 0xF0)  >> 4)*10  + (hours & 0x0F)) & 0x3F;   // Transform hours
    year     =   (year & 0xC0) >> 6;                                     // Transform year
    day      =  (((day & 0x30) >> 4)*10    + (day & 0x0F)) & 0x3F;      // Transform day
    month    =  (((month & 0x10)  >> 4)*10 + (month & 0x0F)) & 0x3F;    // Transform month
}

now I need to go the other way to send BCD to the RTC when set the time
 
As I said in post 7 to go from binary to bcd add (bin/10)*6.
I.E
bcd=bin+((bin/10)*6);
OR
num+=(num/10)*6;

Mike.
 
Gentlemen, thank you for your input. Pommie I had looked at Ian's algorithm in post #8 but had read right over yours, thanks for pointing it out.
 
Code:
typedef unsigned char bool;
union
{
    struct
    {
        bool pumptimer1:1;      /*using the bits to flag if */
        bool pumptimer2:1;      /*a run timer is in use*/
        bool pumptimer3:1;
        bool pumptimer4:1;
        bool pumptimer5:1;
        bool pumptimer6:1;
        bool pumptimer7:1;
        bool pumptimer8:1;
    };
}pmptmr;        //pump timer status

  ++bb;
    timer 0x01 <<bb;            //bit shift to the left "bb" times
    if (pmptmr && timer &= On)
    {
        I2C1_MasterRead(*pdata,3,RTCC,*pflag);
    }
I am setting up a timer to start and stop a pump. The RTC has 240x8 bytes that I am using in five byte blocks. I am using the above struct to flag which timers are in use. I am tring to mask pmptmr with timer (and bit shifting) to pick out which are active but I need help to get it to work
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…