The other problem is that you are abusing volatile variables. When you use them you need to turn interrupts off. temp doesn't need to be volatile, but you should turn them off when you use counter. In your check for 100, use temp instead.
The other problem is that you are abusing volatile variables. When you use them you need to turn interrupts off. temp doesn't need to be volatile, but you should turn them off when you use counter. In your check for 100, use temp instead.