Engineer's Asylum

Set bits to clear

#1

I have seen a case where the bits are cleared in order to enable/set the corresponding bit in the register. Why is that and how does it work internally?

#2

Clearing a bit in a register implies changing the previous value ( 0 or 1 ) in the bit to 0. If you are considering registers in a microcontroller, each of these registers has their own predefined functions. Toggling any bit in these register switches the function of the register altogether.

For example, The TMR0ON bit in the T0CON Register is set to 1 to enable the timer and cleared to turn off the timer, in a PIC microcontroller. At the same time, the T08BIT in the T0CON Register is used to configure the timer as an 8-bit/16-bit timer.

To know more about registers, follow the below link.