Tutorial Microcontroller MCS-51 ATMEL ISP
 

 

Super MCS51 Trainer

Standart MCS51 Trainer

Standart AVR Trainer

Programmer USBASP

Standart ARM Trainer

 

 

9. Interrupt

The 80C51 provides 5 interrupt sources. These are shown in Figure 17. The External Interrupts INT0 and INT1 can each be either level-activated or transition-activated, depending on bits IT0 and IT1 in Register TCON. The flags that actually generate these interrupts are bits IE0 and IE1 in TCON. When an external interrupt is generated, the flag that generated it is cleared by the hardware when the service routine is vectored to only if the interrupt was transition-activated. If the interrupt was level-activated, then the external requesting source is what controls the request flag, rather than the on-chip hardware.

The Timer 0 and Timer 1 Interrupts are generated by TF0 and TF1, which are set by a rollover in their respective Timer/Counter registers (except see Timer 0 in Mode 3). When a timer interrupt is generated, the flag that generated it is cleared by the on-chip hardware when the service routine is vectored to.

The Serial Port Interrupt is generated by the logical OR of RI and TI. Neither of these flags is cleared by hardware when the service routine is vectored to. In fact, the service routine will normally have to determine whether it was RI or TI that generated the interrupt, and the bit will have to be cleared in software.

All of the bits that generate interrupts can be set or cleared by software, with the same result as though it had been set or cleared by hardware. That is, interrupts can be generated or pending interrupts can be canceled in software.

Each of these interrupt sources can be individually enabled or disabled by setting or clearing a bit in Special Function Register IE (Figure 18). IE also contains a global disable bit, EA, which disables all interrupts at once.

Priority Level Structure
Each interrupt source can also be individually programmed to one of two priority levels by setting or clearing a bit in Special Function

Register IP (Figure 19). A low-priority interrupt can itself be interrupted by a high-priority interrupt, but not by another low-priority interrupt. A high-priority interrupt can’t be interrupted by any other interrupt source.

If two request of different priority levels are received simultaneously, the request of higher priority level is serviced. If requests of the same priority level are received simultaneously, an internal polling sequence determines which request is serviced. Thus within each priority level there is a second priority structure determined by the polling sequence as follows:

Source Priority Within Level
1. IE0 (highest)
2. TF0
3. IE1
4. TF1
5. RI+TI (lowest)

Note that the “priority within level” structure is only used to resolve simultaneous requests of the same priority level. The IP register contains a number of unimplemented bits. IP.7, IP.6, and IP.5 are reserved in the 80C51. User software should not write 1s to these positions, since they may be used in other 8051 Family products.



Interrupt Enable Registe ( IE )

MSB
LSB
EA
X
X
ES
ET1
EX1
ET0
EX0

BIT
SYMBOL
FUNCTION
IE.7 EA
Disables all interrupts. If EA=0, no interrupt will be acknowledged. If EA=1, each interrupt source is individually enabled or disabled by setting or clearing its enable bit.
IE.6 - -
IE.5 - -
IE.4 ES
Enables or disables the Serial Port interrupt. If ES=0, the Serial Port interrupt is disabled.
IE.3 ET1
Enables or disables the Timer 1 Overflow interrupt. If ET1=0, the Timer 1 interrupt is disabled.
IE.2 EX1
Enables or disables External Interrupt 1. If EX1=0, External interrupt 1 is disabled.
IE.1 ET0
Enables or disables the Timer 0 Overflow interrupt. If ET0=0, the Timer 0 interrupt is disabled.
IE.0 EX0
Enables or disables External interrupt 0. If EX0=0, External interrupt 0 is disabled.

Interrupt Priority Register ( IP )

MSB   LSB
X
X
X
PS
PT1
PX1
PT0
PX0

Note:
BIT
SYMBOL
FUNCTION
IP.7
-
-
IP.6
-
-
IP.5
-
-
IP.4
PS
Defines the Serial Port interrupt priority level. PS=1 programs it to the higher priority level.
IP.3
PT1
Defines the Timer 1 interrupt priority level. PT1=1 programs it to the higher priority level.
IP.2
PX1
Defines the External Interrupt 1 priority level. PX1=1 programs it to the higher priority level.
IP.1
PT0
Enables or disables the Timer 0 interrupt priority level. PT0=1 programs it to the higher priority level.
IP.0
PX0
Defines the External Interrupt 0 priority level. PX0=1 programs it to the higher priority level.

 

Source
Vector Address
IE0
0003H
TF0
000BH
IE1
0013H
TF1
001BH
RI + TI
0023H

9.1. Timer Interrupt Application

Pulse Generator

The next example implements Timer 0 interrupt for generates pulse generator. The interrupt generated from Timer 0 overflows TF0. At the begining data 10000000b will be send out to P0, and after 0,05 second data will be complemented be 01111111 and send out to P0 again.


Microcontroller Timer Interrupt

Figure 5.2.1. Clock generator with Timer 0 interrupt

 

Step 1st
Build the circuit as shown in figure 5.2.1. As you seen on figure 5.2.1. P0.0 is connected to Osciloscope. Remember, that all we want to do with this lesson is generate clock via P0.0 with timer 0 interrupt

Step 2nd
In this step, you must tipe the assembly program to make your Timer get action, we assume that you have already known the editor, we used MIDE-51 to edit the program. ( Download File : exp521.zip )

In this experiment, we use Timer 0 mode 1 with vector address timer 0 interrupt 0BH. Note that in this mode, with a 12 Mhz crystal frequency, the timer over flows every 65,536 microsecond. To generate interrupt every 50000 microsecond ( 0,05 second ) then 65536-50000=15536 d = 3CB0 h and data tobe loaded TL0 = B0h dan TH0 = 3Ch.

   Org 0h
   sjmp Start
   Org 0bh
Ljmp Interrupt_Timer0
;
Start: mov A,#10000000b
       call InitTimer
;
Forever:
       mov P0,A
       sjmp Forever ; 
;
Interrupt_Timer0:
       mov tl0,#0b0h
       mov th0,#03ch
       cpl A
       reti
; 
InitTimer:
       mov TMOD,#00000001b;Timer/Counter 0 as Timer
       mov tl0,#0b0h
       mov th0,#03ch
       setb ET0           ;Enable Timer 0 Interrupt 
       setb EA            ;Enable Master Interrupt 
       setb TR0           ;Start Running
       ret
;   
end

Step 3rd
Safe your assembly program above, and name it with int1.asm (for example) Compile the program that you have been save by using MIDE-51, see the software instruction.

Step 4th
Download your hex file ( int1.hex ) into the microcontroller by using Microcontroller ATMEL ISP software, see the instruction.After download this hex file you'll see the action of Timer 0 Interrupt ( of course if your cable connection and your program are corrected ).

NEXT