|= and +=

Can anybody explain what is the difference between operators “|=” and “+=” when using them with registers?

For example, using “TIMSK+= 1<<1” works good, but “TIMSK|= 1<<1” kills delay command.

Addition is slightly different to or. Its no different to using chars, registers are just values too.

6 | 2 = 6 6 + 2 = 8

If you do not know what the operators are: http://www.cplusplus.com/doc/tutorial/operators/#bitwise http://www.cplusplus.com/doc/tutorial/operators/#logical

Well, "+=" performs an addition, so if the bit you are trying to set is already 1, then its going to change to zero, and a 1 gets carried to the next most significant bit and so on. Not a suitable operation to perform on a control register, I would say.

"|=" performs logical OR, so if the bit in question is already 1 then no change is made.

Paul

Thanks a lot, I get it.