Struggling with the basics

Coming back to electronics after a long break, I am struggling with the basics. I never was a programmer, but have done a little C programming, but for PCs, not chip-level stuff. Right now, can someone clarify the _BV() thing.

TCCR3A = _BV(COM3A1) | _BV(COM3B1) | _BV(WGM31) | _BV(WGM30);

Is this to write to the TCCR, with only the specified bits set ? COM3B1 etc' being substituted at compile time to match the specific uC, with the bit number in the TCCR ?

Is there a corresponding instruction to clear a bit ?

Post the whole code, in code tags.

There's a robust set of bitwise operators available to you in C. A quick overview can be see here.

A number of threads addressing different aspects turn up under a forum search for "_BV()".

Anding with the bitwise not of the bit value(s) works.

TCCR3A &= ~( _BV(COM3A1) );

TCCR3A &= ~( _BV(COM3A1) | _BV(COM3B1) | _BV(WGM31) | _BV(WGM30) );

Each bit within a control register (ex, COM3A1) is #defined in the compiler-supplied include files to the number of that bit within the register (ie, a number from 0 to 7). _BV() is a (rather trivial) macro that turns that into a byte with the corresponding bit set (ie, _BV(COM3A1) is the same as (1<<COM3A1) ( << is left-bitshift). | is bitwise or.

Be careful when configuring registers like that - are you certain the registers will start off in the correct state for &= and |= to give the results you want in all cases? If I know what value I want the whole register to be set to, I assign it directly instead of using &= or |= )