This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

WHAT WILL HAPPEN WHEN INTERRUPT OCCUS IN 8051?

Can please tell me what will happen when interrupt occurs in 8051??

I have gone through books but still i am not clear in the following..

1. Will INT disable all inerrupts before jumping to ISR

2. Do we need to PUSH the contents of register?

3.Difference between RET and reti

4. Do we need to clear the flag before RETI in all cases? (i.e Serial INT/ TIMER/ EXT INT?

I will be hapy if anybody help me in knowing sequence of events occurs as soon as interrupt occurs in 8051

Parents
  • HV,

    This is certainly something you could find out in any good 8051 datasheet or textbook, but here are the general answers:

    1. When an interrupt is serviced by the hardware, it disables all interrupts AT THE SAME PRIORITY LEVEL. So, if a low-priority interrupt occurs, at the moment the MCU decides to service it, all other low priority interrupts are disabled until your ISR issues a RETI instruction to re-enable them.

    2. You need to push the contents of any registers you plan to use and then pop them at the end of the routine. This prevents your "main code" from running into problem when registers change outside its control. Alternatively, you can use the 8051's register bank switching to speed things up. If all of your low-priority ISRs use register bank 1, while all your main code uses register bank 0, you could just switch register banks and then switch back before returning from the ISR.

    3. RETI, as I suggested above, tells the processor to re-enable interrupts at the same priority as the one currently being serviced. If you use a RET command, your interrupt system will be essentially shut down for that priority level.

    4. As you have probably noticed in reading the datasheet, for some interrupts, the hardware clears the flag automatically when it vectors to the ISR. In other cases (like the serial interrupt), you must clear it in software. The general reasoning is this: If a SINGLE ISR could have MULTIPLE flags that caused it (like RI/TI in the serial int), then you will have to clear the flag yourself.

    Hope some of that helps.

    -Jay Daniel

Reply
  • HV,

    This is certainly something you could find out in any good 8051 datasheet or textbook, but here are the general answers:

    1. When an interrupt is serviced by the hardware, it disables all interrupts AT THE SAME PRIORITY LEVEL. So, if a low-priority interrupt occurs, at the moment the MCU decides to service it, all other low priority interrupts are disabled until your ISR issues a RETI instruction to re-enable them.

    2. You need to push the contents of any registers you plan to use and then pop them at the end of the routine. This prevents your "main code" from running into problem when registers change outside its control. Alternatively, you can use the 8051's register bank switching to speed things up. If all of your low-priority ISRs use register bank 1, while all your main code uses register bank 0, you could just switch register banks and then switch back before returning from the ISR.

    3. RETI, as I suggested above, tells the processor to re-enable interrupts at the same priority as the one currently being serviced. If you use a RET command, your interrupt system will be essentially shut down for that priority level.

    4. As you have probably noticed in reading the datasheet, for some interrupts, the hardware clears the flag automatically when it vectors to the ISR. In other cases (like the serial interrupt), you must clear it in software. The general reasoning is this: If a SINGLE ISR could have MULTIPLE flags that caused it (like RI/TI in the serial int), then you will have to clear the flag yourself.

    Hope some of that helps.

    -Jay Daniel

Children