It's basically OK except for a few minor bugs:
1. in main() you change the values of some registers then change them again in the next instruction. Only the last value will be used. Set all the INTCON bits and all the OPTION_REG bits in one instruction each.
2. Dont change the GIE bit inside the interrupt routine. The PIC automatically clears it when an interupt occurs and re-enables it when you leave the interrupt routine.
3. Set the Timer0 interrupt enable in main and leave it set. There's no need to turn it on again in the interrupt routine.
4. It isn't technically wrong to use delay routines inside an interrupt routine but it is considered bad practice. The delay will prevent it leaving the ISR so you could miss other interrupts being triggered.
The reason you are seeing intermittent results is almost certainly due to two factors, the switch contacts will be bouncing and producing more than one pulse to the counter and also you will be missing some presses while in the IRS because of the delays.
A better stategy is to do it like this:
1. Clean up the code as mentioned earlier
2. Declare another variable, I suggest "char Trigger" but the name is up to you to pick.
3. In the ISR simply reset the value in TMR0 ready for the next time, make "Trigger = 1;" then clear the T0IF bit. Remove all the other lines.
4. Inside the while(1) loop, add
Code:
if(Trigger == 1) blink();
Trigger = 0;
Now, the while loop will monitor for the switch being pressed five times (or at least, five pulses coming from it) then run the blink code. The Trigger variable will be set when the interrupt is called but actually do the flashing in the main part of the program.
Brian.