Wednesday, January 18, 2006

8051: Example 7

Using External Interrupt

Here is another example of interrupt execution. An external iterrupt is generated when a logic zero (0) is present on pin P3.2 or P3.3. Depending on which input is active, one of two routines will be executed:
A logic zero (0) on the P3.2 pin initiates execution of interrupt routine Isr_Int0, thus incrementing number in register R0 and copying it to port P0. Logic zero on the P3.3 pin initiates execution of subroutine Isr_Int1, number in register R1 is incremented by 1 and then copied to port P1.
In short, each press on push buttons INT0 and INT1 will be counted and immediately shown in binary format on appropriate port (LED which emitts light represents a logic zero (0)).
Using External Interrupt
;************************************************************************
;* PROGRAM NAME : Int.ASM
;* DESCRIPTION : Program counts interrupts INT0 generated by appearance of high-to-low
;* transition signal on pin P3.2 Result appears on port P0. Interrupts INT1 are also 
;* counted up at the same time. They are generated byappearing high-to-low transition
;* signal on pin P3. The result appears on port P1.
;************************************************************************

;BASIC DIRECTIVES

$MOD53
$TITLE(INT.ASM)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING

;RESET VECTORS

        CSEG     AT     0
        JMP      XRESET               ; Reset vector

        ORG      003H                 ; Interrupt routine address for INT0
        JMP      Isr_Int0
        ORG 013H                      ; Interrupt routine address for INT1
        JMP      Isr_Int1

        ORG      100H
XRESET:
        MOV      TCON,#00000101B      ; Interrupt INT0 is generated by appearing
                                      ; high-to-low transition signal on pin P3.2
                                      ; Interrupt INT0 is generated by appearing
                                      ; high-to-low transition signal on pin P3.3
        MOV      IE,#10000101B        ; Interrupt enabled
        MOV      R0,#00H              ; Counter starting value
        MOV      R1,#00H
        MOV      P0,#00H              ; Reset port P0
        MOV      P1,#00H              ; Reset port P1

LOOP:   SJMP     LOOP                 ; Remain here

Isr_Int0:
        INC R0                        ; Increment value of interrupt INT0 counter
        MOV P0,R0
        RETI

Isr_Int1:
        INC R1                        ; Increment value of interrupt INT1 counter
        MOV P1,R1
        RETI
        END                           ; End of program