What error you are getting: Did you try debug the code?
Suggestions:
1. disable all interrupts before setting & enabling required interrupts and clearing flags
2. Enable Global Interrupts GIE/GIEH/GIEL only after all the required interrupts set and enabled (best putting just before while(1))
3. See the example sequence (for clarity purpose only).
INTCON = 0;
setting TRIS, PORT, ANSEL(if reqd) registers
clear Interrupts Flags and setting corresponding Interrupts (example, Timer0)
Enable GIE/GIEH/GIEL
while(1){
}
T0CONbits.TMR0ON = 1; //Disable Timer0
You enabled again TMR0 not disabled.
Of course, you don't need to disable here(as per your current requirement). Also, clear Interrupt flags only after you completed your required action, for example, lit the LED. Otherwise, if any further timer0 interrupt occurred before completing your work, it may reenter in to the ISR again and your pending work becomes void. Consider the following sequence.
Code:
INTCONbits.TMR0IF = 0; //Clear Timer 0 Interrupt Flag
LATDbits.LATD4 =~LATDbits.LATD4 ;// toggle the led
this will be better:
Code:
LATDbits.LATD4 =~LATDbits.LATD4 ;// toggle the led
INTCONbits.TMR0IF = 0; //Clear Timer 0 Interrupt Flag