I'd like only to add. Never use following code, for example status |= 0B00000101; for clearing status register when you want to clear bit 0 and 2:
The instruction is internally performed as read modify write so the result is:
Let status register is 0B01010101 and you want to clear bit 2 and 0 and you use code as presented above (status |= 0B00000101; ).
Internal procedure performs following:
read : temp = 0B01010101
modify : temp = temp | 0B00000101
write : 0B01010101 -> status
The result is that all bits in the status regfister are cleared. This is standard mistake I have met a lot of times.
So, you wave to write direct number with corresponding bits (bits you want clear) set to 1 to clear them.
Best regards,
Ladislav