Beruflich Dokumente
Kultur Dokumente
2
Faculty of Engineering & Technology ©M. S. Ramaiah University of Applied Sciences
Session Topics
• Interrupts
• Interrupt Model
• Type 1 And Type 2 – Event is remembered when interrupt is
disabled
• Interrupt Vectors
• RI and TI flags and interrupt
• Program for serial communication interrupt
• Programming timer interrupt concept
• Program for timer interrupt
• Programming for External Hardware Interrupt
• Program for External Interrupt
3
Faculty of Engineering & Technology ©M. S. Ramaiah University of Applied Sciences
Interrupts
• Allow program to respond to events when they occur, Allow
program to ignore events until the occur
• External events e.g.:
• UART ready with/for next character
• Signal change on pin
• Action depends on context
• # of edges arrived on pin
5
Faculty of Engineering & Technology ©M. S. Ramaiah University of Applied Sciences
Type 1 And Type 2 – Event is remembered when
interrupt is disabled
TYPE-1
• When interrupt is enabled again, interrupt takes place, and flag is reset
TYPE-2
• If interrupt is not enabled, and level goes away before the interrupt is
enabled, nothing happens
6
Faculty of Engineering & Technology ©M. S. Ramaiah University of Applied Sciences
Interrupt Vectors
• If interrupts are not used, this memory can be used as part of the
program
7
Faculty of Engineering & Technology ©M. S. Ramaiah University of Applied Sciences
RI and TI flags and interrupt
• Received interrupt is raised when entire frame of data, including the
stop bit, is received
• Use of serial COM in 8051: the serial interrupt is used mainly for
receiving the data serially. For example phone call receiver
8
Faculty of Engineering & Technology ©M. S. Ramaiah University of Applied Sciences
Program for serial communication interrupt
• Write a program in which the 8051 reads data from p1 and writes it to
p2 continuously while giving a copy of it to the serial COM port to
transferred serially. Assume that XTAL= 11.0592MHZ. Set the baud rate
at 9600
org 0
LJMP main
Org 23H
Org 30h
• ORG 100H
• END
11
Faculty of Engineering & Technology ©M. S. Ramaiah University of Applied Sciences
Programming timer interrupt
• Roll over timer flag and interrupt:
if the timer interrupt in the IE register enabled, whenever the timer rolls
over, TF is raised, and micro controller is interrupted in whatever it is
doing, and jumps to the interrupt vector table to service the ISR
• The ISR for timer 0 is located starting at memory location 000BH since
it is small enough to fit the address space allocated to this interrupt
12
Faculty of Engineering & Technology ©M. S. Ramaiah University of Applied Sciences
Programming timer interrupt cont.
• We enabled the timer 0 interrupt with “MOV IE, #1000010B” in main B
• In the ISR for timer 0, notice that there is no need for a “clr tfo”
instruction before the RETI instruction
13
Faculty of Engineering & Technology ©M. S. Ramaiah University of Applied Sciences
Program for timer interrupt
• Write a program that displays a value of ‘y’ at port 0 and N at port 2
and also generates a square wave of 10KHZ with timer 0 in mode2 at
port pin p1.2. XTAL= 22MHZ
• Org 0000H
• RETI
14
Faculty of Engineering & Technology ©M. S. Ramaiah University of Applied Sciences
Programming timer interrupt cont.
• Org 0030H ; a location after the interrupt vectors
• End
15
Faculty of Engineering & Technology ©M. S. Ramaiah University of Applied Sciences
Programming External Hardware Interrupts
• The 8051 as 2 external hardware interrupt hardware : INT0 and INT1
• They are located on pins 3.2 and p3.3 of port 3, respectively
• There are 2 types of actions for the external hardware interrupts:
• level triggered
• edge triggered
• In level triggering mode INT0 and INT1 are high if low level signal is
applied to them, it triggers the interrupt. then controller stop the work
and JUMP to vector table for providing service
• INT0 and INT1 low level triggered interrupts at edge triggering. TCON
register holds the bits and all information among triggering
16
Faculty of Engineering & Technology ©M. S. Ramaiah University of Applied Sciences
Program for External Interrupt
• Generate from all pins of port 0, a square wave which is half the
frequency of the signal applied at INT0 pin( pin No. 3.2).
org 0000H
LJMP MAIN
;-- ISR for the hardware Interrupt INTO
Org 0003 H
CPL P0
RETI
Org 0030H
Main SETB TCON.0 ; make INT0 an edge triggered interrupt
Mov IE, #81H ; enable hardware interrupt INT0
Here : SJMP Here
End 17
Faculty of Engineering & Technology ©M. S. Ramaiah University of Applied Sciences
Summary
• Use of serial COM in 8051: the serial interrupt is used mainly for
receiving the data serially. For example phone call receiver
18
Faculty of Engineering & Technology ©M. S. Ramaiah University of Applied Sciences