Delay using interrupt

Home Forums Microcontrollers PIC Microcontroller Delay using interrupt

Tagged: ,

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #13782
    sonar_abhi
    Participant

    Hello Guys,

    I am trying to implement a delay using timer0 interrupt. I’ll just post an abstraction of the code in mikroc

    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?

     

     

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
>