MC Module-4
MC Module-4
4th Semester
Interrupt Programming: Basics of Interrupts, 8051 Interrupts,
Programming Timer Interrupts, Programming Serial
Communication Interrupts, Interrupt Priority in 8051(Assembly
Language only) ( Text book 2- 3.6, Text book 1- 11.1,11.2,11.4,
11.5)
Contents:
• 8051 Interrupts
• 8051 Assembly language interfacing
• 8051 Assembly language programming to generate an external
interrupt using a switch
• 8051 C programming to generate a square waveform on a port pin
using a Timer interrupt
• Interfacing 8051 to ADC-0804
• Interfacing 8051 to DAC
• Interfacing 8051 to LCD
• Interfacing 8051 to Stepper motor
• 8051 Assembly language interfacing programming
• A single microcontroller can serve several devices by two ways, Interrupts and
Polling.
Interrupts:
• Whenever any device needs its service, the device notifies the microcontroller
by sending it an interrupt signal
• Upon receiving an interrupt signal, the microcontroller interrupts whatever it is
doing and serves the device
• The program which is associated with the interrupt is called the interrupt
service routine (ISR) or interrupt handler
• Advantage of interrupt: The advantage of interrupts is that the microcontroller
can serve many devices (not all at the same time)
• Each devices can get the attention of the microcontroller based on the assigned
priority
• For the polling method, it is not possible to assign priority since it checks all
devices in a round-robin fashion
• The microcontroller can also ignore (mask) a device request for service
01/22/2025 Dept of ECE, SJCIT 4
Microcontrollers. 4th sem
Polling
• The microcontroller continuously monitors the status of a given
device.
• When the conditions met, it performs the service.
• After that, it moves on to monitor the next device until
everyone is serviced
• Disadvantage of polling: Polling can monitor the status of
several devices and serve each of them as certain conditions are
met
• The polling method is not efficient, since it wastes much of
the microcontrollers time by polling devices that do not
need service
• The microcontroller cannot ignore (mask) a device request
for service
01/22/2025 Dept of ECE, SJCIT 5
Microcontrollers. 4th sem
INTERRUPT SERVICE ROUTINE (ISR)
• Solution:
• MOV IE,#10010110B ;enable serial, timer 0, EX1
Another way to perform the same manipulation is
• SETB IE.7 ;EA=1, global enable
• SETB IE.4 ;enable serial interrupt
• SETB IE.1 ;enable Timer 0 interrupt
• SETB IE.2 ;enable EX1
• The instruction in Step (a) assigned a higher priority to INT1 than the others;
• therefore, when INT0,INT1, and TF0 interrupts are activated at the same time, the
8051 services INT1 first, then it services INT0, then TF0.
• This is due to the fact that INT1 has a higher priority than the other two because of
the instruction in Step (a). The instruction in Step (a) makes both the INT0 and
• TF0 bits in the IP register 0. As a result, the sequence in Table is followed which
gives a higher priority to INT0 over TF0
Assume that after reset, the interrupt priority is set the instruction MOV
IP,#00001100B. Discuss the sequence in which the interrupts are
serviced.
Solution:
The instruction “MOV IP #00001100B” (B is for binary) and timer 1
(TF1)to a higher priority level compared with the reset of the interrupts.
However, since they are polled according to Table,
they will have the following priority.
• Highest Priority External Interrupt 1 (INT1)
• Timer Interrupt 1 (TF1)
• External Interrupt 0 (INT0)
• Timer Interrupt 0 (TF0)
• Lowest Priority Serial Communication (RI+TI)
01/22/2025 Dept of ECE, SJCIT 19
Microcontrollers. 4th sem
INTERRUPT INSIDE AN INTERRUPT
• The 8051 contains four 8-bit parallel ports namely PORT 0, PORT 1,
PORT 2 and PORT 3.
• Ports are used to send or receive data and each bit of port can be
configured as an input or output.
• PORT 0 is also used as low order address and data pins(AD0 – AD7)
• PORT 2 is used as high order address pins(A8-A15)
• PORT 3 is used by timers, serial ports, external interrupts and for
sending control signals(RD,WR).
• Each port is associated with port registers P0 (80 H) ,P1(90 H),P2(0A0
H) and P3(0B0 H)
• These ports supports all the three types of buses namely Address bus
(A0-A15), Data bus(D0-D7) and Control bus(RD,WR,PSEN,ALE,EA).
PERIPHERALS: TIMER 0 and TIMER 1.
• Each timer consists of two 8-bit register
01/22/2025 Dept of ECE, SJCIT 35
Microcontrollers. 4th sem
INTERFACING LCD TO 8051
• The stack is a LIFO section of RAM used by the CPU to store information
temporarily.
• This information could be data or an address
• The register used to access the stack is called the SP (stack pointer) register
• the stack pointer in the 8051 is only 8 bit wide, which means that it can
take value of 00 to FFH
• When the 8051 is powered up, the SP register contains value 07. Hence
RAM location 08 is the first location being used for the stack by the 8051
• The storing of a CPU register in the stack is called a PUSH
• SP is pointing to the last used location of the stack
• As we push data onto the stack, the SP is incremented by one
• Loading the contents of the stack back into a CPU register is called a POP
• With every pop, the top byte of the stack is copied to the register specified
by the instruction and the stack pointer is decremented once