1. The *noInterrupts()*function has no argument; so, none of the 25 available masksable interrupts of the ATmega328 is supposed to be associated with this function. (Reset interrupt is a nonmaskable interrupt.)
2. * noInterrupts()* function, when executed, places LL at the I-bit (Global Interrupt Enable Bit) of SREG-register. Therefore, the noInterrupts() function prevents the MCU from responding to any kind of interrupts except reset.
3. The delay(arg) function contains the built-in interrupt sub routine ISR(TIMER0_OVF_vect) like the Serial.begin(arg1, arg2)() function of UART, which contains built-in ISR(USART_RX_vect) interrupt sub routine. There is no way that a user/programmer can get access to the codes of the delay() function and the ISR(TIMER_OVF_vect) routine.
The MCU executes the ISR(TIMER0_OVF_vect) routine in response to TOV0 (T0 Overflow) interrupt. The TOV0 interrupt may occur at every 1 ms interval or at some other value. Let us assume that the TOV0 will occur at 1 ms interval and its clocking frequency is set at 250 kHz clkTC0 ( 16 MHz / 64 = 250 kHz). As a result, the pre-set value for TC0 becomes 0x06 (0x100 - 250 = 0x100 - 0xFA). The Conceptual Structure of delay(1000) function stands as:
delay(1000)
{
Initialize To as normal up counter
//Set clkTCO at 250 kHz
Load preset count of 0x06 to make a rollover (TOV0 flag set) at 1 ms interval
Initialize milliSecondCounter = 0x00
Start T0 at 250 kHz clkTC0
WAIT: wait for TOV0 interrupt
if (millisecondCounter ! = 1000)
goto WAIT
Return to the calling (Mother) Program
}
ISR(TIMER0_OVF_vect)
{
Re-load preset value into TC0
milliSeconCounter = milliSecondCounter + 1
Return to calling program from ISR
}
4. If we place the noInterrupts() function before the delay(1000) function, the MCU will still enter into the delay() function; Timer-0 will be running but looping from pre-set count ----> rollover count ----> 0x00 ----> 0xFF ----> 0x00 ---. It is so; because, the ISR(TIMER0_OV0_vect) function is not being executed, no re-load of preset value, and no increment of milliSecondCounter. The MCU will be locked in an infinite loop; waiting and waiting for T0 overflow interrupt; but, it never occurs! (Interrupt logic is disabled!)
5. The consecutive placement of noInterrupts() and interrupts() functions before the delay() function has no affect on the functioning of the delay() function.
6. The 25 maskable interrupts have their own trigger sources and interrupt vectors. No two or more interrupts are of same kind.
7. When two interrupts arrive at the same, then the interrupt having lower numerical value for the interrupt vector is given the priority.
** **8.** **
If a higher priority interrupt arrives while a lower priority is in service, the higher priority one will be remembered if it is a latched type interrupt like TOV1/TOV2, and it will be serviced once the current ISR is completed and re-enables the interrupt logic. denied. This is due to the fact that the interrupt logic became disabled when the MCU vectored at lower priority ISR. There is no scope for deferred service.
9. When roll-over occurs at the end of 1 ms time period, the TOV0 flag assumes LH-state. This flag can generate interrupt signal for the MCU provided the interrupt logic is made active via Global Interrupt Enable Bit and Timer-0 Overflow Interrupt Enable Bit.