3.3.3 Change Register Bit Field Configurations Using Bit Positions
The example below shows how to update a register bit field using bit positions to set the new configuration. The current configuration is cleared, and the new configuration is set, in a single line of code.
USART0.CTRLB = (USART0.CTRLB & ~((1 << USART_RXMODE0_bp) | (1 << USART_RXMODE1_bp))) | (0 << USART_RXMODE0_bp) | (1 << USART_RXMODE1_bp);
Note: The
(0 <<
USART_RXMODE0_bp)
line is added simply for readability, but it can be
removed.USART0.CTRLB = (USART0.CTRLB & ~((1 << USART_RXMODE0_bp) | (1 << USART_RXMODE1_bp))) | (1 << USART_RXMODE1_bp);