Microprocessing Systems - Chapter 6: Interrupts - Lê Chí Thông

ISR vs. Subroutine

• Similarity: CPU executes another program and then returns to

the original program.

• Difference: It is NOT known when the main program suspends

execution

pdf27 trang | Chuyên mục: Vi Xử Lý – Vi Điều Khiển | Chia sẻ: tuando | Lượt xem: 311 | Lượt tải: 0download
Tóm tắt nội dung Microprocessing Systems - Chapter 6: Interrupts - Lê Chí Thông, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
Lê Chí Thông
Practice Problem 2
Write a program using Timer 1 and interrupt to output data from A to 
Port 1 every 100 us. Use crystal 12 MHz.
ORG 0000H
LJMP MAIN
ORG 001BH ;Interrupt vector of Timer 1
MOV P1,A
RETI
ORG 0030H
MAIN: MOV TMOD,#20H
MOV TH1,#-100
SETB TR1
SETB EA
SETB ET1
SJMP $
END
Ref. I. Scott Mackenzie 30Lê Chí Thông
ĐH Bách Khoa TP.HCM Lê Chí Thông
sites.google.com/site/chithong 16
Practice Problem 3
Write a program using Timer and interrupt to send data from A to 
serial port (UART 8 bit, 1200 baud) every 250 us. Use crystal 12 MHz.
Ref. I. Scott Mackenzie 31Lê Chí Thông
Practice Problem 3
Write a program using Timer and interrupt to send data from A to 
serial port (UART 8 bit, 1200 baud) every 250 us. Use crystal 12 MHz.
Ref. I. Scott Mackenzie 32Lê Chí Thông
ORG 0000H
LJMP MAIN
ORG 000BH
ACALL PHAT
RETI
ORG 0030H
MAIN: MOV TMOD,#22H 
MOV SCON,#52H
MOV TH1,#-26
SETB TR1
MOV TH0,#-250
SETB TR0
SETB EA
SETB ET0
SJMP $
PHAT: JNB TI,$
CLR TI
MOV SBUF,A
RET
END
ĐH Bách Khoa TP.HCM Lê Chí Thông
sites.google.com/site/chithong 17
Timer (16 bit) Interrupt
Write a program using Timer 0 and interrupt to create a 1 kHz square 
wave on P1.1. (Crystal 12 MHz)
Ref. I. Scott Mackenzie 33Lê Chí Thông
Timer (16 bit) Interrupt
Write a program using Timer 0 and interrupt to create a 1 kHz square 
wave on P1.1. (Crystal 12 MHz)
Ref. I. Scott Mackenzie 34Lê Chí Thông
ORG 0000H
LJMP CTCHINH
ORG 000BH
LJMP CTNGATTIMER0
ORG 0030H
CTCHINH:
MOV TMOD,#01H
MOV TH0,#HIGH(-500)
MOV TL0,#LOW(-500)
SETB TR0
SETB EA
SETB ET0
SJMP $
CTNGATTIMER0:
CPL P1.1
CLR TR0
MOV TH0,#HIGH(-500)
MOV TL0,#LOW(-500)
SETB TR0
RETI
END
ĐH Bách Khoa TP.HCM Lê Chí Thông
sites.google.com/site/chithong 18
Timer (16 bit) Interrupt
Write a program using Timer 0 and interrupt to create a 1 kHz square 
wave on P1.1. (Crystal 12 MHz)
Ref. I. Scott Mackenzie 35Lê Chí Thông
ORG 0000H
LJMP CTCHINH
ORG 000BH
LJMP CTNGATTIMER0
ORG 0030H
CTCHINH:
MOV TMOD,#01H
SETB EA
SETB ET0
SETB TF0 ; Ép ngắt
SJMP $
CTNGATTIMER0:
CPL P1.1
CLR TR0
MOV TH0,#HIGH(-500)
MOV TL0,#LOW(-500)
SETB TR0
RETI
END
Practice Problem 1 
Write a program using Timer 1 and interrupt to create a 100 Hz 
square wave on P1.2. (Crystal 24MHz)
Ref. I. Scott Mackenzie 36Lê Chí Thông
ĐH Bách Khoa TP.HCM Lê Chí Thông
sites.google.com/site/chithong 19
Practice Problem 1 
Write a program using Timer 1 and interrupt to create a 100 Hz 
square wave on P1.2. (Crystal 24MHz)
Ref. I. Scott Mackenzie 37Lê Chí Thông
ORG 0000H
LJMP CTCHINH
ORG 001BH
LJMP CTNGATTIMER1
ORG 0030H
CTCHINH:
MOV TMOD,#10H
SETB EA
SETB ET1
SETB TF1 ; Ép ngắt
SJMP $
CTNGATTIMER1:
CPL P1.2
CLR TR1
MOV TH1,#HIGH(-10000)
MOV TL1,#LOW(-10000)
SETB TR1
RETI
END
Practice Problem 2 
Write a program using Timer 1 and interrupt to complement P1.2 
every 1 sec. (Crystal 12 MHz)
Ref. I. Scott Mackenzie 38Lê Chí Thông
ĐH Bách Khoa TP.HCM Lê Chí Thông
sites.google.com/site/chithong 20
Practice Problem 2 
Write a program using Timer 1 and interrupt to complement P1.2 
every 1 sec. (Crystal 12 MHz)
Ref. I. Scott Mackenzie 39Lê Chí Thông
ORG 0000H
LJMP CTCHINH
ORG 001BH
LJMP CTNGATTIMER1
ORG 0030H
CTCHINH:
MOV TMOD,#10H
SETB EA
SETB ET1
SETB TF1 ; Ép ngắt
SJMP $
CTNGATTIMER1:
CPL P1.2
CLR TR1
MOV TH1,#HIGH(-10000)
MOV TL1,#LOW(-10000)
SETB TR1
RETI
END
Two Square Waves Using Timer Interrupts
Write a program using interrupts to create 7 kHz and 500 Hz square 
waves on P1.7 and P1.6. (Crystal 12 MHz)
Ref. I. Scott Mackenzie 40Lê Chí Thông
ĐH Bách Khoa TP.HCM Lê Chí Thông
sites.google.com/site/chithong 21
Two Square Waves Using Timer Interrupts
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0ISR
ORG 001BH
LJMP T1ISR
ORG 0030H
MAIN: MOV TMOD,#12H
MOV IE,#8AH
MOV TH0,#-71
SETB TR0
MOV TH1,#HIGH(-1000)
MOV TL1,#LOW(-1000)
SETB TR1
SJMP $
Write a program using interrupts to create 7 kHz and 500 Hz square 
waves on P1.7 and P1.6
T0ISR: CPL P1.7
RETI
T1ISR: CPL P1.6
CLR TR1
MOV TH1,#HIGH(-1000)
MOV TL1,#LOW(-1000)
SETB TR1
RETI
END
Ref. I. Scott Mackenzie 41Lê Chí Thông
Character Output Using Interrupts
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP SPISR
ORG 0030H
MAIN: MOV TMOD,#20H
MOV TH1,#-26
SETB TR1
MOV SCON,#42H
MOV IE,#90H
MOV A,#20H
SETB TI
SJMP $
Write a program using interrupts to continually transmit the ASCII code set 
(excluding control codes) to a terminal attached to the 8051’s serial port (1200 
baud, 12 MHz crystal). The ASCII codes consist of 95 graphic codes (20H to 7EH) and 
33 control codes (00H to 1FH, and 7FH).
SPISR: CJNE A,#7FH,SKIP
MOV A,#20H
SKIP: MOV SBUF,A
INC A
CLR TI
RETI
END
Ref. I. Scott Mackenzie 42Lê Chí Thông
ĐH Bách Khoa TP.HCM Lê Chí Thông
sites.google.com/site/chithong 22
Character Output Using Interrupts (2)
Write a program using interrupts to continually transmit the ASCII code set 
(excluding control codes) to a terminal attached to the 8051’s serial port (1200 
baud, 12 MHz crystal). The ASCII codes consist of 95 graphic codes (20H to 7EH) and 
33 control codes (00H to 1FH, and 7FH).
Ref. I. Scott Mackenzie 43Lê Chí Thông
Character Output Using Interrupts (2)
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP SPISR
ORG 0030H
MAIN: MOV SCON,#52H
MOV TMOD,#20H
MOV TH1,#-26
SETB TR1
MOV A,#20H
MOV IE,#90H
SJMP $
Write a program using interrupts to continually transmit the ASCII code set 
(excluding control codes) to a terminal attached to the 8051’s serial port (1200 
baud, 12 MHz crystal). The ASCII codes consist of 95 graphic codes (20H to 7EH) and 
33 control codes (00H to 1FH, and 7FH).
SPISR: CLR TI
MOV SBUF,A
INC A
CJNE A,#7FH,SKIP
MOV A,#20H
SKIP: RETI
END
Ref. I. Scott Mackenzie 44Lê Chí Thông
ĐH Bách Khoa TP.HCM Lê Chí Thông
sites.google.com/site/chithong 23
Furnace Controller
Using interrupts, design an 8051 furnace controller that keeps a building at 20oC ± 1oC.
Temperature sensors are connected to /INT0 and /INT1 and provide /HOT and /COLD 
signals. The furnace ON/OFF solenoid is connected to P1.7.
/HOT = 0 if T > 21oC
/COLD = 0 if T < 19oC
P1.7 = 1 : Furnace ON
P1.7 = 0 : Furnace OFF
P3.2
P3.3
Ref. I. Scott Mackenzie 45Lê Chí Thông
Furnace Controller
ORG 0000H
LJMP MAIN
ORG 0003H
E0ISR: CLR P1.7 ;turn furnace off
RETI
ORG 0013H
E1ISR: SETB P1.7 ;turn furnace on
RETI
ORG 0030H
MAIN: MOV IE,#85H ;enable external 0 & 1 interrupts
SETB IT0 ;negative edge triggered for external 0
SETB IT1 ;negative edge triggered for external 1
SETB P1.7 ;turn furnace on
JB P3.2,SKIP ;if T > 21 degrees, 
CLR P1.7 ; turn furnace off
SKIP: SJMP $ ;do nothing
END
Using interrupts, design an 8051 furnace controller that keeps a building at 20oC ± 1oC.
Ref. I. Scott Mackenzie 46Lê Chí Thông
ĐH Bách Khoa TP.HCM Lê Chí Thông
sites.google.com/site/chithong 24
Intrusion Warning System (1)
Design an intrusion warning system using interrupts that sounds a 400 Hz tone using 
loudspeaker connected to P1.7 whenever a door sensor connected /INT0 makes a 
high-to-low transition.
P3.2
Ref. I. Scott Mackenzie 47Lê Chí Thông
Intrusion Warning System (1)
Design an intrusion warning system using interrupts that sounds a 400 Hz tone using 
loudspeaker connected to P1.7 whenever a door sensor connected /INT0 makes a 
high-to-low transition.
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP E0ISR
ORG 001BH
LJMP T1ISR
ORG 0030H
MAIN: SETB IT0
MOV TMOD,#10H
MOV IE,#81H
SJMP $
E0ISR: SETB TF1
SETB ET1
RETI
T1ISR: CLR TR1
MOV TH1,#HIGH(-1250)
MOV TL1,#LOW(-1250)
CPL P1.7
SETB TR1
RETI
END
Ref. I. Scott Mackenzie 48Lê Chí Thông
ĐH Bách Khoa TP.HCM Lê Chí Thông
sites.google.com/site/chithong 25
Intrusion Warning System (2)
P3.2
50 ms
Design an intrusion warning system using interrupts that sounds a 400 Hz tone for 
50 ms (using loudspeaker connected to P1.7) whenever a door sensor connected 
/INT0 makes a high-to-low transition.
Ref. I. Scott Mackenzie 49Lê Chí Thông
Intrusion Warning System (2)
Design an intrusion warning system using interrupts that sounds a 400 Hz tone for 
50 ms (using loudspeaker connected to P1.7) whenever a door sensor connected 
/INT0 makes a high-to-low transition.
ORG 0000H
LJMP MAIN
ORG 0003H 
LJMP E0ISR
ORG 000BH
LJMP T0ISR
ORG 001BH
LJMP T1ISR
ORG 0030H
MAIN: SETB IT0
MOV TMOD,#11H
MOV IE,#81H
SJMP $
E0ISR: MOV TH0,#HIGH(-50000)
MOV TL0,#LOW(-50000)
SETB TR0
SETB TF1
SETB ET0
SETB ET1
RETI
T0ISR: CLR TR0
CLR ET0
CLR ET1
RETI
T1ISR: CLR TR1
MOV TH1,#HIGH(-1250)
MOV TL1,#LOW(-1250)
CPL P1.7
SETB TR1
RETI
END
Ref. I. Scott Mackenzie 50Lê Chí Thông
ĐH Bách Khoa TP.HCM Lê Chí Thông
sites.google.com/site/chithong 26
Intrusion Warning System (3)
Design an intrusion warning system using interrupts that sounds a 400 Hz tone for 
1 second (using loudspeaker connected to P1.7) whenever a door sensor connected 
/INT0 makes a high-to-low transition.
P3.2
Ref. I. Scott Mackenzie 51Lê Chí Thông
Intrusion Warning System (3)
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP E0ISR
ORG 000BH
LJMP T0ISR
ORG 001BH
LJMP T1ISR
ORG 0030H
MAIN: SETB IT0
MOV TMOD,#11H
MOV IE,#81H
SJMP $
E0ISR: MOV R7,#20
SETB TF0
SETB TF1
SETB ET0
SETB ET1
RETI
T0ISR: CLR TR0
DJNZ R7,SKIP
CLR ET0
CLR ET1
LJMP EXIT
SKIP: MOV TH0,#HIGH(-50000)
MOV TL0,#LOW(-50000)
SETB TR0
EXIT: RETI
T1ISR: CLR TR1
MOV TH1,#HIGH(-1250)
MOV TL1,#LOW(-1250)
CPL P1.7
SETB TR1
RETI
END
Design an intrusion warning system using interrupts that sounds a 400 Hz tone for 
1 second (using loudspeaker connected to P1.7) whenever a door sensor connected 
/INT0 makes a high-to-low transition.
Ref. I. Scott Mackenzie 52Lê Chí Thông
ĐH Bách Khoa TP.HCM Lê Chí Thông
sites.google.com/site/chithong 27
53
References
Lê Chí Thông
• I. Scott Mackenzie, The 8051 Microcontroller
• Các tài liệu trên Internet không trích dẫn hoặc không ghi tác 
giả

File đính kèm:

  • pdfmicroprocessing_systems_chapter_6_interrupts_le_chi_thong.pdf
Tài liệu liên quan