This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to move TL2 and TH2 into a 16-bit variable?

How can I move the two sfr's, TH2:TL2, into an unsigned int variable?

TIA
John

Parents
  • I presume you want to read the T2 without stopping it.

    unsigned int t2_read(void)
    {
        union
        {
            unsigned int  i;
            unsigned char b[2];     /* MSB is [0], LSB is [1]  */
        } u;
    
        do
        {
            u.b[0] = TH2;
            u.b[1] = TL2;
        } while (TH2 != u.b[0]);    /* Loop if TL2 rolled over */
    
        return (u.i);
    }

Reply
  • I presume you want to read the T2 without stopping it.

    unsigned int t2_read(void)
    {
        union
        {
            unsigned int  i;
            unsigned char b[2];     /* MSB is [0], LSB is [1]  */
        } u;
    
        do
        {
            u.b[0] = TH2;
            u.b[1] = TL2;
        } while (TH2 != u.b[0]);    /* Loop if TL2 rolled over */
    
        return (u.i);
    }

Children