Waiting for Bits to Change using Assembly and C
You often have to wait for an event, such as wait until the timer overflows,
or until someone
pushes a switch. Here is how to wait until a particular bit of a register is set or cleared.
loop: brclr TFLG2,#$80,loop while((TFLG2 & 0x80) == 0) ; while(!(TFLG2 & 0x80)) ;
loop: brset PORTB,#$01,loop while((PORTB & 0x01) == 0x01) ; while(PORTB & 0x01) ;