Introduction: Interrupts With 8051

  • An interrupt is an external or internal event that interrupts the microcontroller to inform it that a device needs its service.
  • Interrupts vs. Polling
  • A single microcontroller can serve several devices.
  • There are two ways to do that: –
  • Interrupts
  • Polling.
  • The program which is associated with the interrupt is called the interrupt service routine (ISR) or interrupt handler.

Step 1: Steps in Executing an Interrupt:

  • Finish current instruction and saves the PC on stack.
  • Jumps to a fixed location in memory depend on type of interrupt
  • Starts to execute the interrupt service routine until RETI (return from interrupt)
  • Upon executing the RETI the microcontroller returns to the place where it was interrupted. Get pop PC from stack

Step 2: Interrupt Sources:

Original 8051 has 6 sources of interrupts

1. Reset

2. Timer 0 overflow

3. Timer 1 overflow

4. External Interrupt 0

5. External Interrupt 1

6. Serial Port

Step 3: Interrupt Vectors:

Each interrupt has a specific place in code memory where program execution (interrupt service routine) begins.

External Interrupt 0: 0003h

Timer 0 overflow: 000Bh

External Interrupt 1: 0013h

Timer 1 overflow: 001Bh

Serial: 0023h

Step 4: Interrupt Enable (IE) Register:

• All interrupt are disabled after reset

• We can enable and disable them by IE

Step 5: Interrupt Priorities:

• What if two interrupt sources interrupt at the same time?

• The interrupt with the highest PRIORITY gets serviced first. • All interrupts have a power on default priority order.

1. External interrupt 0 (INT0)

2. Timer interrupt0 (TF0)

3. External interrupt 1 (INT1)

4. Timer interrupt1 (TF1)

5. Serial communication (RI+TI) •

Priority can also be set to “high” or “low” by IP reg.

Step 6: Interrupt Priorities (IP) Register:

IP.7: reserved

IP.6: reserved

IP.5: timer 2 interrupt priority bit(8052 only)

IP.4: serial port interrupt priority bit

IP.3: timer 1 interrupt priority bit

IP.2: external interrupt 1 priority bit

IP.1: timer 0 interrupt priority bit

IP.0: external interrupt 0 priority bit

Step 7: External Interrupt Example: (INT0):

Simulation interrupt is given in above.

C Code of External interrupt (INT0):

Attachments

Step 8:

Any Query related Embedded System , IOT and Raspberry PI go to My Blog:

embeddedbymedhavi