0% found this document useful (0 votes)
5 views7 pages

Labsheet 3 BERZ 2404 Interrupt Service Routine

This document outlines Lab 3 for the Microcontroller Technology course at Universiti Teknikal Malaysia Melaka, focusing on Interrupt Service Routine (ISR). The lab objectives include understanding interrupt registers, creating a basic ISR, and implementing an interrupt-based application using PIC microcontrollers. It provides detailed procedures for constructing circuits, programming in C, and simulating the results using Proteus ISIS software.

Uploaded by

hisyamuddin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views7 pages

Labsheet 3 BERZ 2404 Interrupt Service Routine

This document outlines Lab 3 for the Microcontroller Technology course at Universiti Teknikal Malaysia Melaka, focusing on Interrupt Service Routine (ISR). The lab objectives include understanding interrupt registers, creating a basic ISR, and implementing an interrupt-based application using PIC microcontrollers. It provides detailed procedures for constructing circuits, programming in C, and simulating the results using Proteus ISIS software.

Uploaded by

hisyamuddin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

FAKULTI TEKNOLOGI DAN KEJURUTERAAN

ELEKTRONIK DAN KOMPUTER


UNIVERSITI TEKNIKAL MALAYSIA MELAKA

MICROCONTROLLER TECHNOLOGY

BERZ 2404 SEMESTER 1 SESI 2025/2026

LAB 3: Interrupt Service Routine

NAME OF GROUP 1.
MEMBERS &
MATRIX NUMBER
2.

3.

COURSE

DATE

NAME OF INSTRUCTOR 1.

2.

EXAMINER’S COMMENT VERIFICATION STAMP

TOTAL MARKS

1
1.0 OBJECTIVES

• To determine the contents of the interrupt related registers


• To create the basic interrupt service routine
• To implement an interrupt-based PIC application.

2.0 EQUIPMENT/COMPONENTS

i) CCS C Compiler software.


ii) Proteus ISIS software
iii) PTK40A PIC Training Kit Module.

3.0 SYNOPSIS & THEORY

Most programs use interrupts in their regular execution. The purpose of the
microcontroller is mainly to respond to changes in its surrounding. In other words, when an event
takes place, the microcontroller does something... For example, when you push a button on a
remote controller, the microcontroller will register it and respond by changing a channel, turn the
volume up or down etc. If the microcontroller spent most of its time endlessly checking a few
buttons for hours or days, it would not be practical.

This is why the microcontroller has learned a trick during its evolution. Instead of
constantly checking each pin or bit, the microcontroller delegates the ‘wait issue’ to a
‘specialist’, which will respond only when something attention-worthy happens. The signal
which informs the central processor unit about such an event is called an INTERRUPT.

INTERRUPT SYSTEM REGISTERS

When an interrupt request arrives, it doesn’t mean that an interrupt will automatically
occur because it must also be enabled by the user (from within the program). Because of this,
there are special bits used to enable or disable interrupts. It is easy to recognise them by the
letters IE contained in their names (stands for Interrupt Enable). Besides, each interrupt is
associated with another bit called the flag, which indicates that an interrupt request has arrived
regardless of whether it is enabled. They are also easily recognisable by the last two letters in
their names- IF (Interrupt Flag).

As seen, everything is based on a simple and efficient idea. When an interrupt request
arrives, the flag bit is set first.

This condition will be completely ignored if the appropriate IE bit is not set (0).
Otherwise, an interrupt occurs! If several interrupt sources are enabled, it is necessary to detect
the active one before the interrupt routine starts execution. Source detection is performed by
checking flag bits.
It is important to know that the flag bits are not automatically cleared by software while
the interrupt routine execution is in progress. If we neglect this detail, another interrupt will
occur immediately after returning to the main program, even though there are no more requests
for its execution. Simply put, the flag, as well as the IE bit, remain set.
INTCON Register

INTCON or Interrupt Configuration register is purposely used for setting up and


enabling interrupt function. This 8-bit register is also being used to observe the related interrupt
flaTwo bits in this register are associated with the external interrupt RB0 module, Global
Interrupt Enable bit (GIE), and external interrupt enable bit (INTE), as shown in Figure 3.1. The
details configuration is shown in Figure 3.1.

Figure 3.1 INTCON register bit configuration definition

The GIE bit enables all unmasked interrupts and disables all interrupts simultaneously.
The PEIE bit enables all unmasked peripheral interrupts and disables all peripheral interrupts.
This doesn’t concern Timer TMR0 and PORTB interrupt sources.
CCS C Interrupt Functions

Action Description Example

INTERRUPT CLEAR Clears peripheral interrupt clear_interrupt(int_timer0);

INTERRUPT DISABLE Disables peripheral disable_interrupts(int_timer0);


interrupt
INTERRUPT ENABLE Enables peripheral enable_interrupts(int_timer0);
interrupt
INTERRUPT ACTIVE Checks if interrupt flag set interrupt_active(int_timer0);

INTERRUPT EDGE Select interrupt trigger ext_int_edge(H_TO_L);


edge.

PIC16F877 Primary Interrupts

Interrupt Label Interrupt Source


GLOBAL Use to enable all interrupt sources.

INT_EXT External interrupt detection on RB0.

INT_RB Change on Port B detection

INT_RTCC Timer 0 overflow (same as TIMER0)

INT_TIMER0 Timer 0 overflow (same as RTCC)

//CCS Code Skeleton with RB0/INT Interrupt ISR


#include <16F877A.h>
#use delay(crystal=20000000)
#fuses HS,NOWDT,NOPROTECT

#INT_EXT
void ext_isr(void)
{
clear_interrupt(INT_EXT); // Clear external interrupt flag bit
}

void main()
{
ext_int_edge(H_TO_L); // External interrupt edge from high to low
clear_interrupt(INT_EXT); // Clear external interrupt flag bit
enable_interrupts(INT_EXT); // Enable external interrupt
enable_interrupts(GLOBAL); // Enable global interrupts
while(TRUE){} //Endless loop
}

Code Listing 3.1: CCS C Code Skeleton With ISR


4.0 PROCEDURE
PART1

1. Construct the following schematic diagrams in Proteus, as shown in Figure 4.1. You can reuse the
schematic created in the previous lab session.

Figure 4.1: Main Circuit diagram

Figure 4.2: Sub I/O Circuit diagram

2. By using high-level language programming (C Language), develop a program to perform an


up-counter by embedding the related interrupt service routine (ISR) into the program. You
can refer to the code skeleton in the example in Code Listing 3.1.

3. Declare an int8-type global variable (declared outside the main () function) and name the
variable as COUNTER. Use the variable inside your ISR to increase the value when the
interrupt occurs.
4. Upon starting/reset the program, make the PIC to turn ON LEDs on PORTD for 1 second
then turn OFF the LEDs by adding the necessary instructions in the main() function. The
purpose is to verify the condition of the LEDs in PORTD.

5. After complete, compile your source code and get the .hex file.

6. Load the .hex file generated from the above source code and simulate the circuit using Proteus ISIS.

7. You can observe the COUNTER variable value in PIC memory. Click Debug menu and
select 3.PIC CPU -> 3.Data Memory. You also can view the variable content using Debug -
> 2.Watch Window.

Figure 4.3: Proteus ISIS PIC Data Memory Access


8. You can retrieve the variable’s memory location in the .sym file

Location 0x27

.
Figure 4.4: How to Locate Variable Address in .sym File

9. Then export the .hex file to PTK40A PIC Training Kit and observe your result upon
successful simulation.

10. Verify the output with the lab instructor.


PART2: EXERCISE

Modify the Proteus design file by changing the connections of SW1, SW2 and SW3 to RB4,
RB5, and RB6 pins.
By using a high-level language programming (C language) and interrupt module, develop a
PIC-based program that contains an interrupt service routine (ISR) to perform the
requirements listed below:
• When SW1 is pressed, the program will increment a counter variable and display
the counter value on PortD LEDs.
• When SW2 is pressed, the program will decrease the counter variable and display
the counter value on PortD LEDs.
• When SW3 is pressed, the program will RESET the counter variable to 0 and
display the counter value on PortD LEDs.
Compile the source code and simulate the program using Proteus ISIS only.
Verify the output with the lab instructor.

5.0 RESULTS AND DISCUSSION

Kindly discuss the lab’s results and findings.

6.0 CONCLUSION

Conclude what you have learned in this lab session.

You might also like