De La Salle University – Dasmariñas College of
Engineering, Architecture & Technology
Electronics Engineering Program
Experiment 3
TIMER0:Delay using Polling and Interrupt
Name: Manuel Victor T. Dudang Date Performed: February 20, 2024
Professor: Engr. Emmanuel T. Longares, PECE Date Submitted: February 20, 2024
Introduction
Expanding upon the foundation laid by TIMER0 in microcontroller programming, this
experiment embarks on a thorough exploration of two distinct methodologies for establishing
precise time delays: polling and interrupt-driven techniques. The initial focus lies on the polling
method, characterized by its proactive approach of continuously monitoring specific conditions
until the desired time interval has elapsed. This straightforward strategy proves invaluable in
scenarios where simplicity and consistent behavior are paramount, offering a reliable means of
timing control.
Conversely, the experiment also delves into interrupt-driven delays, leveraging the
microcontroller's ability to promptly respond to external events. Interrupt-driven techniques
present a paradigm shift in timing control, offering enhanced efficiency and accuracy,
particularly beneficial for applications necessitating responsiveness to various inputs alongside
managed time delays. By comprehensively examining both polling and interrupt-driven
methodologies, participants are equipped with a holistic understanding of TIMER0, thereby
gaining essential proficiencies for proficient microcontroller-based system development.
Through the utilization of MPLAB X IDE and relevant hardware components, this experiment
provides a hands-on opportunity for participants to explore the intricacies of TIMER0
implementation. Successful navigation of code compilation, debugging, and circuit verification
processes underscore the effectiveness of MPLAB X IPE in facilitating seamless program
transfer and thorough validation. Overall, this experiment serves as a pivotal learning experience,
empowering participants with practical skills and knowledge essential for navigating the
complexities of microcontroller programming and real-world applications.
Data Gathered
Figure 1. Code in the MPLAB X IDE in Delay using Polling
In introducing delay using polling, the student made use of the "TMR0HasOverflowOccured()"
function to check for overflow occurrences in the Timer0 module, allowing for accurate timing
control within the program loop.
Figure 2. Code in the MPLAB X IDE in Delay using Timer Interrupt
In delay using timer interrupt, the student coded in tmr0.c and added an interrupt handler, along
with including t0.h and mcc.h for proper integration and functionality. This code is responsible
for managing the timing operations within the program, ensuring precise and efficient
execution of tasks based on the timer interrupt signals.
Figure 2. Actual circuit
Figure 2 illustrates the actual circuit on the breadboard, serving to verify the functionality of the
code. The result confirms a 250ms delay achieved through delay polling, mirroring the
outcome observed when employing timer interrupt.
Summary
In summary, the experiment involves utilizing and evaluating a Microchip microcontroller via
MPLAB X IDE. Figure 1 displays the code implementing a delay through polling, specifically
modifying the D5 LED's state. A crucial step involves clearing the overflow flag, indicated as
"TMR0IF = 0," ensuring accurate handling of overflow events within the program. Figure 2
confirms successful code compilation in MPLAB X IDE, validating its bug-free status.
Subsequent steps encompass debugging and generating a hex file for programming the
microcontroller using MPLAB X IPE. Figure 3 depicts the Microchip's successful programming,
allowing assessment of the physical circuit's operational status. Additionally, Figure 4 showcases
the creation of the main.c file in MPLAB X IDE, indicating efficient code template development.
Furthermore, Figure 5 demonstrates successful TIMER0 debugging using Interrupts without a
delay, highlighting code integrity. Figure 6 presents debugging with a 2-second delay, while
Figure 7 illustrates the physical circuit on a breadboard for further evaluation. Overall, the
experiment compellingly demonstrates MPLAB X IPE's capability in transferring programs to
microchips, enabling comprehensive testing and validation.
Conclusion
In conclusion, this experiment provides a comprehensive exploration into the utilization of
TIMER0 in microcontroller programming, focusing on the implementation of precise time delays
using both polling and interrupt-driven methodologies. Through the utilization of MPLAB X
IDE and relevant hardware components, participants were able to gain practical insights into
these techniques. The polling method, characterized by its simplicity and consistent behavior,
proved effective for scenarios where straightforward timing control is required. On the other
hand, interrupt-driven delays demonstrated enhanced efficiency and accuracy, particularly
suitable for applications demanding responsiveness to external events alongside managed time
delays. By traversing both approaches, participants acquired essential proficiencies in
microcontroller-based system development, laying a solid foundation for further exploration and
innovation in this domain. Through successful code compilation, debugging, and circuit
verification, the experiment underscored the effectiveness of MPLAB X IPE in facilitating
seamless program transfer and thorough validation processes. Overall, this experiment serves as
a valuable learning experience, equipping participants with practical skills and knowledge
essential for navigating the intricacies of microcontroller programming and real-world
applications.
References
Reynolds, M. (n.d.). Timer 0 Delay using Polling Example in MPLAB® Code Configurator -
Developer Help. https://developerhelp.microchip.com/xwiki/bin/view/products/mcu-
mpu/8bitpic/peripherals/timers/tm0exam/
The Timer Modules - Timer0 - Microchip PIC microcontroller. (n.d.).
https://www.pcbheaven.com/picpages/The_Timer_Modules/