sonar_abhi
New Member
Hello Guys,
I am trying to implement a delay using timer0 interrupt. I'll just post an abstraction of the code in mikroc
The above code does not work as I expected. Can somebody please point out the mistake I am making or suggest a better way for achieving a 100 ms delay using interrupt?
I am trying to implement a delay using timer0 interrupt. I'll just post an abstraction of the code in mikroc
C:
void inittimer()
{
//Timer initialization for a 32ms interrupt
}
void interrupt()
{
//interrupt code;
delayvariable++;
}
void main()
{
TRISB = 0; //PORTB is output
TRISC.F0 = 1; //PORTC Pin 0 is input and connected to a switch
if (PORTC.F0 ==0) //check is the button is pressed
{
if (delayvariable==3) //~100ms second delay to check buttton debounce
}
if (PORTC.F0==0) //check if the button is still pressed
{
PORTB = ~PORTB; //toggle PORTB
delayvariable = 0; //reset the delay variable
}
}
}
}
The above code does not work as I expected. Can somebody please point out the mistake I am making or suggest a better way for achieving a 100 ms delay using interrupt?
Last edited by a moderator: