TCS Pune

PIC24 XC16 Timer Interrupt

MPLAB XC16

PIC24 XC16 Timer Interrupt

Build a periodic timer interrupt for a 16-bit PIC24 target.

IDE: MPLAB X IDE with XC16 compilerBoard/MCU: PIC24FJ family development board

Project files

Download project ZIP
Starter — main.c
#include <xc.h>
void __attribute__((interrupt,no_auto_psv)) _T1Interrupt(void){ /* TODO */ }
int main(void){ while(1){} }
Completed — main.c
#include <xc.h>
void __attribute__((interrupt,no_auto_psv)) _T1Interrupt(void){ IFS0bits.T1IF=0; LATBbits.LATB0^=1; }
int main(void){ TRISBbits.TRISB0=0; T1CON=0x8030; PR1=15624; IFS0bits.T1IF=0; IEC0bits.T1IE=1; while(1){} }

Toolchain and dependencies

IDE requirements

MPLAB X IDE with XC16 compiler

Compatible targets

PIC24FJ family development board

Libraries/dependencies

  • PIC24 device family pack

Serial output examples

Serial Monitor

Timer interrupt active

Serial Plotter

Compiler-error explanations

new declaration for _T1Interrupt

Likely cause: Interrupt function signature/attribute is wrong

Fix: Use the XC16 interrupt attribute for the selected device

Timer period is incorrect

Likely cause: FCY or prescaler assumption is wrong

Fix: Calculate PR1 using the real instruction clock

Submit your code

Log in to edit the starter files and submit your solution for instructor review.

Log in to submit
Ready when you are

Need help with your laptop or computer?

Send us the model and fault details. Start your repair request online or contact TCS Pune directly.

WA