Hai...
I have not verified your code completely and i have not written the full code.
I am making a suggestion to you to connect the switch with the external interrupt pin (INT). So when ever you press the switch, your code will go to interrupt routine.
Now follow the code as below
Code:
void interrupt()
{
if (INTCON.INTF == 1)
{
if(first_time == 0) //check are you visiting interrupt first time or not
{
LED = 1;
}
else
{
t2con.tmr2on=0;
restart_the_timer ();
}
INTCON.INTF = 0;
}
else if (PIR1.TMR2IF == 1)
{
PIR1.TMR2IF = 0;
LED = ~LED;
t2con.tmr2on=0;
}
}
This will help you to set the LED port pin at the first time. Then it will restart the timer.
All the best