(assuming 8 bit device) If you are reading 16 bit or 32 bit variable in main, it is possible to interrupt in the middle of that operation.. update the variable and return to main. Then part of the bytes read will be from the old value and some will be from the updated value.
What you need to do is declare the variable "volatile" and disable interrupts when you are using the variable (this is called atomic operation).
C:
int main(void)
{
volatile uint32_t addcount;
uint32_t copyOfAddcount;
while(1)
{
/* Atomic operation */
cli(); /* Disable global interrupts */
copyOfAddcount = addcount;
sei(); /* Enable global interrupts */
}
}
More robust way would be to first save the state of global interrupts, disable them and after atomic operation is done, restore the state of global interrupts.