Practical Workshop
Embedded C
Program Electrical Engineering
Level 1st year
Supervisor : Pr. JENKAL Wissam
Lab 2: Interrupt Handling on PIC16F877
Introduction
This lab aims to evaluate your ability to design, implement, and simulate interrupt-based systems using
the PIC16F877 microcontroller. You are expected to write the embedded C code yourself based on the
problem scenarios described below, simulate your work in Proteus, and document your results.
Tools and Software
- MikroC (for Embedded C programming and compilation)
- Proteus (for circuit design and simulation)
Part 1: External Interrupt on RB0
Design and implement a system where a push-button connected to pin RB0 triggers an external
interrupt. When the button is pressed, the system should toggle the state of an LED connected to RB1.
You are required to:
- Write your own Embedded C code to implement this behaviour.
- Properly configure RB0 as input and RB1 as output.
- Ensure the interrupt is triggered on a rising edge.
- Debug the program and explain the process.
- Simulate the system using Proteus and demonstrate the LED toggling on button press.
- Document and explain your implementation.
Part 2: Interrupt-on-Change on RB4–RB7
Develop a system that uses interrupt-on-change functionality on pins RB4 to RB7. Each time a change is
detected on any of these pins, an LED connected to RB0 should toggle its state.
You are required to:
- Write your own Embedded C code to handle the interrupt-on-change.
- Properly configure RB4 to RB7 as inputs and RB0 as output.
- Debug the program and explain the process.
- Simulate your circuit in Proteus using push-buttons on RB4–RB7.
1
- Show the toggling of the LED on RB0 whenever any of the buttons is pressed or released.
- Document your observations and explanation of your design choices.
Deliverables
- Complete, well-commented Embedded C source code for each part.
- Proteus circuit files showing working simulation.
- Screenshots of simulation results.
- A short report explaining your implementation and answers to reflection questions.
Reflection Questions
1. What are the main differences between external interrupt and interrupt-on-change?
2. Why is it important to clear interrupt flags manually?
3. What are the challenges of handling multiple interrupts in embedded systems?
Debugging Tasks
As part of the lab, you are required to debug your own code and circuit implementation. Here are some
common scenarios to test and document:
1. What happens if you do not enable the global interrupt?
2. What if you forget to clear the interrupt? For each debugging case:
- Describe what went wrong.
- Explain how you identified the issue.