.title "EL308" .sbttl "Simple example on timer1 interrupt" .equ __24FJ256GB110, 1 .include "p24FJ256GB110.inc" .global __reset ;The label for the first line of code. .global __T1Interrupt ;Declare Timer 1 ISR name global .bss .section .const,psv .text ;Start of Code section __reset: mov #__SP_init, W15 ; Initalize the Stack Pointer mov #__SPLIM_init, W0 ; Initialize the Stack Pointer Limit Register mov W0, SPLIM nop ; Add NOP to follow SPLIM initialization call init_LED call init_timer do_nothing: bra do_nothing ; ::::::::::::::::: ; ::: Functions ::: ; ::::::::::::::::: init_timer: bclr T1CON, #TON ; turn timer1 OFF bset T1CON, #TCKPS1 bclr T1CON, #TCKPS0 ; set prescaler to 64 bclr T1CON, #TCS ; select internal clock mov #0x0000, W0 mov W0, TMR1 ; clear TMR1 register mov #15625, W0 mov W0, PR1 ; set timer1 period to 31250 -> f=2e6/64/31250=2 Hz bclr IPC0, #14 bclr IPC0, #13 bset IPC0, #12 ; set timer1 priority to 001 bclr IFS0, #T1IF ; clear timer1 interrupt status flag bset IEC0, #T1IE ; enable timer1 interrupts bset T1CON, #TON ; turn timer1 ON return init_LED: bclr TRISF, #0 bclr TRISF, #1 bclr TRISF, #2 bclr TRISF, #3 ; LED array return ; ::::::::::::::::::::::::::::::::::::::::: ; ::: Timer 1 Interrupt Service Routine ::: ; ::::::::::::::::::::::::::::::::::::::::: __T1Interrupt: push.s ; push shadow registers btg PORTF, #0 bclr IFS0, #T1IF ; Clear the Timer1 Interrupt flag Status pop.s ; pop shadow registers retfie ; Return from Interrupt Service routine .end ; End of program code in this file