There are a couple of bad habits in your code, some of which will hurt you now and some will get you in the future.
Andre has already mentioned the use of a delay in the ISR. An ISR is designed to stop the normal flow of your program, do something that must be done immediately and then let the normal program execution continue. Adding in a delay will hold up your normal program execution. In your case the ISR is designed to flash LED2 10 times and take 10 seconds to do it. While that is happening LED1 which is supposed to be flashing on and off every 6 mSec (see below) will stop flashing.
Having LED1 flash every 6 mSec (3mSec on and 3mSec off) is WAY to fast if you are wanting to see the LED flash with your eyes. Your eyes can see things slower than about 30Hz so you should make the delays about 15mSec as a minimum and probably much longer. Of course if you are looking at the signal on an oscilloscope then what you have is fine.
The device you are using has a single interrupt vector that will be called whatever the source of the interrupt. At the moment you are only allowing 1 interrupt source to trigger the ISR and so you are OK. However as soon as you want another interrupt source to be active at any time in your application, then you need to use the standard coding approach of testing both the IE and IF bits of the interrupt. In your cast that would mean code such as
Code:
void interrupt isr(void)
{
if( INTCONbits.INTF && INTCONbits.INTE)
{
// Do whatever is needed here
INTCONbits.INTF = 0;
}
// Test for other interrupt sources here
}
If you follow Andre's good advice about using flags, then you must declare the flag to be 'volatile'. That tells the compiler that it can be changed within an ISR and so not to (for example) put the flag value into a register and think that it will always reflect the true value of the flag.
Using a mechanical device such as a switch or a button means that you must handle 'contact bounce'. While you think you push the button once, the actual contacts can make and brake multiple times over several milli-seconds. When you connect the button or switch to an interrupt pin, then each of those bounces will trigger the ISR (which, as mentioned above, should only take microseconds to complete). There are multiple ways you can debounce a switch or button (Google will show you many) but my preferred technique is to set up a timer that calls an ISR every mSec. The ISR checks the pin and compares it with the value it saw last time. If the ISR sees the same value on the pin for (say) 10 times - or 10mSec - then it will record the 'state' of the button. If that is not the same as the previous 'state', then it can set a flag to say 'the button has changed' and your code can then decide if it has been pushed or released. (This is a very quick overview - but it is faster to code than to describe.)
Susan