Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/11/02 22:45
Read: times


 
#34285 - RE: Checking one bit, in a byte Fast
Just extend Erik's example to check a particular bit for change and to only read the register in question once per check:

#define BIT4 (1 << 4)

unsigned char byte;
unsigned char old_byte;

byte = reg; /* Only read register once per check */

if ((old_byte ^ byte) & BIT4)
{
    /* Bit changed. Save new state, then determine
     * exactly what the change was.
     */
    old_byte = byte;

    if (byte & BIT4)
        /* Bit changed from 0 to 1 */;
    else
        /* Bit changed from 1 to 0 */;
}
else
    /* reg's BIT4 did not change */;

Then as Dennis suggested, check your compiler's output and adjust accordingly. Keil's C51 output for the above is quite efficient.

List of 13 messages in thread
TopicAuthorDate
Checking one bit, in a byte Fast            01/01/70 00:00      
RE: Checking one bit, in a byte Fast            01/01/70 00:00      
RE: Checking one bit, in a byte Fast            01/01/70 00:00      
RE: Checking one bit, in a byte Fast            01/01/70 00:00      
RE: Checking one bit, in a byte Fast            01/01/70 00:00      
RE: Checking one bit, in a byte Fast            01/01/70 00:00      
RE: Checking one bit, in a byte Fast            01/01/70 00:00      
Checking 1 bit in a byte Faster than Dan            01/01/70 00:00      
RE: Checking 1 bit in a byte Faster than Dan            01/01/70 00:00      
RE: assembler faster than C            01/01/70 00:00      
RE: Checking 1 bit in a byte Faster than Dan            01/01/70 00:00      
RE: Checking 1 bit in a byte ... Erik            01/01/70 00:00      
RE: Checking one bit, in a byte Fast            01/01/70 00:00      

Back to Subject List