Interrupts Programming
Interrupts Programming
PROGRAMMING
8051 interrupts
Steps in executing an interrupt
Six interrupts in 8051
Enabling and disabling an interrupt
Programming timer interrupts
Programming external hardware
interrupts
Programming the serial communication
interrupts
Interrupts priority in the 8051
1/7/2011 1
o8051 interrupts
• Interrupt is an external and internal event
that interrupts the microcontroller to inform
it that a device needs it service.
1/7/2011 2
oSteps in executing an interrupts
1) IT FINISHES THE INSTRUCTION IT IS EXECUTING AND SAVES THE ADDRESS OF
THE NEXT INSTRUCTION ON THE STACK.
2) IT ALSO SAVES THE CURRENT STATUS OF ALL THE INTERRUPTS INTERNALLY.
3) IT JUMPS TO A FIXED LOCATION IN MEMORY CALLED THE INTERRUPT VECTOR
TABLE THAT HOLDS THE ADDRESS OF THE INTERRUPTS SERVICE ROUTINE.
4) THE MICROCONTROLLER GETS THE ADDRESS OF ISR FROM THE INTERRUPT
VECTOR TABLE AND JUMPS TO IT . IT START TO EXECUTE THE INTERRUPT
SERVICE SUBROUTINE UNTIL IT REACHES THE LAST INSTRUCTION OF THE
SUBROUTINE WHICH IS RETI.
5) UPON EXECUTING THE RETI INSTRUCTION , THE MICROCONTROLLER RETURNS
TO RETURNS TO THE PLACE WHERE IT WAS INTERRUPTED . FIRST ,IT GETS THE
PROGRAM COUNTER ADDRESS FROM THE STACK BY POPPING THE TOP TWO
BYTES OF THE STACK INTO THE PC . THEN IT STARTS TO EXECUTE FROM THAT
ADDRESS.
1/7/2011 3
o SIX INTERRUPTS IN THE 8051
1) RESET : when the reset pin is activated , the 8051 jumps to the address
location 0000.this is the power up reset discussed in the chapter.
2) Two interrupts are set aside for the timers : one for timer 0 and one for
timer 1.memory locations 000BH and 001BHin the interrupt vector table
belong to timer 0 and timer 1, respectively.
3) Two interrupts are aside for hardware external hardware interrupts. Pin
numbers 12 and 13 in port 3 are for the external hardware interrupts
INT0 and INT1 respectively . these external interrupts are also referred
to as EX1 and EX2.memory locations 0003H and 0013H in the interrupt
vector table are assigned to INT0 and INT1 ,respectively.
4) Serial communication ahs a single interrupt that belongs to both receive
and transfer . the interrupt vector table location 0023H belongs to this
interrupt.
1/7/2011 4
oINTERRRUPT VECTOR
TABLE
Interrupt vector table for 8051
1/7/2011 5
o ENABLING AND DISABLING AN
INTERRUPT
Steps in enabling an interrupt:
a) Bit D7 of the IE register must be set to high
to low the rest of register to take effect.
b) If EA=1, interrupts are enabled and will be
responded to if their corresponding bits in IE
are high. If EA=0, no interrupt will be
responded 0, even if the associated bit in
the IE register is high.
1/7/2011 6
INTERRUPT ENABLE REGISTER
EA _ ET2 ES ET1 EX1 ET0 ET1