PIC16F877A PUSH BUTTON – electroSome https://electrosome.com/topic/pic16f877a-push-button/feed/ Sat, 18 Mar 2023 04:34:34 +0000 https://bbpress.org/?v=2.6.9 en-US https://electrosome.com/topic/pic16f877a-push-button/#post-10616 <![CDATA[PIC16F877A PUSH BUTTON]]> https://electrosome.com/topic/pic16f877a-push-button/#post-10616 Tue, 27 Jan 2015 09:47:03 +0000 namratha 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
    }
  }
}
]]>
https://electrosome.com/topic/pic16f877a-push-button/#post-10622 <![CDATA[Reply To: PIC16F877A PUSH BUTTON]]> https://electrosome.com/topic/pic16f877a-push-button/#post-10622 Tue, 27 Jan 2015 11:51:14 +0000 Ligo George 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.

]]>
https://electrosome.com/topic/pic16f877a-push-button/#post-10623 <![CDATA[Reply To: PIC16F877A PUSH BUTTON]]> https://electrosome.com/topic/pic16f877a-push-button/#post-10623 Tue, 27 Jan 2015 12:22:26 +0000 namratha Thanks George.., will try it out …

]]>
https://electrosome.com/topic/pic16f877a-push-button/#post-10626 <![CDATA[Reply To: PIC16F877A PUSH BUTTON]]> https://electrosome.com/topic/pic16f877a-push-button/#post-10626 Wed, 28 Jan 2015 05:10:06 +0000 Ligo George If you want fast incrementing, use like this.

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