An Example of Interrupt Programming
An Example of Interrupt Programming
Description:
In this example, I programmed the 89S52 to work with INT1 interrupt.
It move to port 0 numbers from 0 to 100 respectively and repeatedly
If Pin 13( INT1) is set to 0, it do the interrupt: Read from Port1 and move to
Port0
But as INT1 is back to High, it returns to counting routine, countinue from
the value before interrupt
U1
19 39
XTAL1 P0.0/AD0
38
P0.1/AD1
37
P0.2/AD2
18 36
XTAL2 P0.3/AD3
35
P0.4/AD4
34
P0.5/AD5
33
P0.6/AD6
9 32
RST P0.7/AD7
R3 P2.0/A8
21
U2
1R R2 P2.1/A9
22
1R 23 7 13
P2.2/A10 A QA
29 24 1 12
PSEN P2.3/A11 B QB
30 25 2 11
ALE P2.4/A12 C QC
31 26 6 10
EA P2.5/A13 D QD
27 4 9
P2.6/A14 BI/RBO QE
28 5 15
P2.7/A15 RBI QF
3 14
LT QG
1
P1.0/T2 P3.0/RXD
10 R1
2 11 1R 74LS47
P1.1/T2EX P3.1/TXD
3 12
P1.2 P3.2/INT0
4 13
P1.3 P3.3/INT1
5 14
P1.4 P3.4/T0
6 15
P1.5 P3.5/T1
7 16
P1.6 P3.6/WR
8 17
P1.7 P3.7/RD
AT89C52
ORG 000H
LJMP Main ; Jump to Main
;-----------Main------------
ORG 30H
Main:
Mov IE, #10000100B ; INT1 interrupt enable
Start:
Mov P0, #0 ; all the out put at Pin 0s are
low
LCall Delay ; Call function for 1s delay
Mov P0, #1 ; Output is 1
LCall Delay
Mov P0, #2 ; Output is 2
LCall Delay
Mov P0, #3 ; Output is 3
LCall Delay
Mov P0, #4 ; Output is 4
LCall Delay
Mov P0, #5 ; Output is 5
LCall Delay
Mov P0, #6 ; Output is 6
Lcall Delay
Mov P0, #7 ; Output is 7
LCall Delay
Mov P0, #8 ; Output is 8
LCall Delay
Mov P0, #9 ; Output is 9
LCall Delay
; Function Delay
Delay:
Mov R7,#0FFH ;R7= FF
Loop2: Mov R6,#0FFH ;R6= FF
Loop1: Djnz R6,Loop1 ;Decrease R6 for R6 greater
than zero then jump to Loop1
Djnz R7,Loop2 ;Decrease R7 for R7 greater
than zero then jump to Loop2
Ret ;End the function
Delay and return memory
End ;End program