Delay functions by counting the clock cycle to meet the duration specified. For example, calling delay of 1ms on a 10Mhz circuit, the compiler will calculate the number of clock cycle that it need to track. (In this case, 2500 clock cycle = 1ms).
You won't see this, but when it compile, it will write something like
- CODE: SELECT_ALL_CODE
while(counter <= 2500)
{ do nothing
}
before jumping to the line.
So when you have an interrupt:
1. uC will stop the delay function (hence stop the counter)
2. Begin interrupt routine
3. Finish interrupt routine
4. Resume delay function (resume counter)
The problem with the above, the delay function ignore all the clock cycle which happen during interrupt. If your interrupt take 200uS, the delay function actually prolong to 1.2ms (instead of 1ms).
To overcome this, some people prefer to use timer interrupt. Because timer interrupt function exactly like above, but better as it also continue to count the counter.
Or, write your own delay function:
- CODE: SELECT_ALL_CODE
while(counter <= 2500)
{ do something here
}
Well, people don't usually do this, unless there is something more important, like another even higher priority interrupt.