sonar_abhi
Member level 1
Hello Guys,
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?
Hello Guys,
I am trying to implement a delay using timer0 interrupt. I'll just post an abstraction of the code in mikroc
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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: