I'm planning to make a real-time clock project as a hobby that utilizes a 1ms timer interrupt using a PIC microcontroller. My goal is to accurately count interrupts to keep track of minutes, seconds, hours, days, months, and years.
I have attached the code I've written and a screenshot from the simulator to provide a clearer view of what I've done so far.
I'm interested in measuring the interrupt latency of my PIC microcontroller in this project. Could you please guide me on how to accurately measure interrupt latency time?
Attached Files:

I'm open to any feedback or guidance you can offer. This project is all about learning and having fun with microcontrollers, so I appreciate any help you can provide. @JohnInTX
Thank you in advance for your time and expertise!
I have attached the code I've written and a screenshot from the simulator to provide a clearer view of what I've done so far.
C:
//PIC18F45K80
#include <xc.h>
#include "config.h"
volatile int count = 0; // Declare count as a global variable
void initializeHardware() {
// Set LATx registers to initial states (all low)
LATA = 0x00;
LATB = 0x00;
LATC = 0x00;
LATD = 0x00;
LATE = 0x00;
// Set TRISx registers to configure pins as outputs (all output)
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
TRISD = 0x00;
TRISE = 0x00;
// Additional configuration for unused peripherals
ANCON0 = 0x00; // Set all analog pins to digital mode
ANCON1 = 0x00; // Set all analog pins to digital mode
CM1CON = 0x00; // Turn off Comparator 1
CM2CON = 0x00; // Turn off Comparator 2
ADCON0 = 0x00; // Disable A/D conversion
ADCON1 = 0x00; // Disable A/D conversion
ADCON2 = 0x00; // Disable A/D conversion
}
// Timer0 configuration for a 1ms interrupt
void configureTimer0() {
T0CON = 0x88; // 16-bit mode, 1:256 prescaler
// Preload Timer0 with the values 0xEC for the high byte and 0x78 for the low byte
TMR0H = 0xEC;
TMR0L = 0x78;
// Enable global interrupt (GIE = 1) and Timer0 overflow interrupt (TMR0IE = 1)
INTCON = 0xA0;
}
void main(void) {
initializeHardware();
configureTimer0();
while (1) {
// main code here
}
}
void __interrupt() isr() {
if (TMR0IF == 1) { // Timer0 overflow interrupt flag bit
TMR0IF = 0; // Clear the interrupt flag
count++; // Increment a counter
// Reload Timer0 with the precise preload values for a 1ms interrupt
TMR0H = 0xEC;
TMR0L = 0x78;
}
}
Attached Files:

I'm open to any feedback or guidance you can offer. This project is all about learning and having fun with microcontrollers, so I appreciate any help you can provide. @JohnInTX
Thank you in advance for your time and expertise!
Last edited:






