PIC16F877A PUSH BUTTON

Home Forums Microcontrollers PIC Microcontroller PIC16F877A PUSH BUTTON

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #10616
    namratha
    Participant

    hi am working on pic16f877a , have interfaced pushbutton . If the button is pressed once value will increment by 1 . But, if I press down and hold for long time value should increment fastely . Below is the code for button and am using XC8 complier.

    void main()
    {
      int oldstate;
      oldstate = 0;
      while(1)
      {
        if(RA4 == 1)              // switch
        {
          oldstate = 1;           // update flag
        }
        if(oldstate &&(RA4 == 0))
        {
          val++;
          if(val > 10)
          {
            val = 1;
          }
          oldstate = 0;            // update flag
        }
      }
    }
    
    #10622
    Ligo George
    Keymaster

    Hello, use like this

    if(button pressed)
    {
      __delay_ms(250);
      if(still button pressed)
      {
        //Increment variable here
      }
    }
    

    This will work for single press and long press.

    #10623
    namratha
    Participant

    Thanks George.., will try it out …

    #10626
    Ligo George
    Keymaster

    If you want fast incrementing, use like this.

    if(button pressed)
    {
      __delay_ms(250);
      while(still button pressed)
      {
        //Increment variable here
      }
    }
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
>