I know that OCIE0A=0001 in binary, so would (1<<OCIE0A) just be 0010? I see this being used quite frequently, what is the reason for setting a register to (1<<OCIE0A) and not just setting it to 0010 directly?
I know that OCIE0A=0001 in binary, so would (1<<OCIE0A) just be 0010? I see
Share
Judging from the results of a Google search, it appears* to be the name for the bit that controls “Timer/Counter Output Compare Match A Interrupt”* in the “Timer/Counter Interrupt Mask Register”* of a “8 bit AVR Microcontroller”* Its usage is as follows*:
Where
TIMSK0is* the Timer Interrupt Mask Register*.OCIE0Ais an identifier that (to someone familiar with AVR code*) is more immediately understandable* thanTIMSK0 |= 2*.They using bit identifiers instead of masks since any halfwit compiler can optimize them to the same thing for bit->mask, but going from mask->bit is harder*. So by leaving it as the bitid, it’s easy and fast for all usages*.
On an unrelated note, numbers are values stored as binary in the computer. “Decimal” and “Hex” are representations of those values. So no, OCIE0A is not “hex”. It is a symbol that represents the bit offset of a flag, with the value of 1.
*assumptions everywhere, I know nothing