Connect with us

Blink led at push of button

Discussion in 'Microcontrollers, Programming and IoT' started by Daljeet12, May 2, 2021.

Scroll to continue with content
  1. Daljeet12

    Daljeet12

    24
    0
    Jun 16, 2018
    Hello everyone

    I have PIC16F877A and I write code in C language MPLAB Xc8. I want to blink led for 1 second pressing push button. assume button will stable at 50ms. I want to use periodic timer to sample switch, if I sample at 10 ms interval, the maximum delay will be 50ms. I will poll button every 10ms to check if the button is pressed.

    I want to understand complete algorithms before starting program

    1) Read the button state at every 10 ms
    2) increment count if button is pressed
    3) Save the state of button for one time
    4) Compare previous state with current state of button
    5) repeat for 5 times
    5) if previous state and current state is always same. switch is pressed

    I am struggling to make algorithms please help me
     
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    11,313
    2,593
    Nov 17, 2011
    Why? Your list is an algorithm.

    Here's a tutorial on debouncing switches with a PIC.
     
    Daljeet12 likes this.
  3. Daljeet12

    Daljeet12

    24
    0
    Jun 16, 2018
    I saw tutorial that is not example of timer. I have mentioned I was looking timer based approach

    Yahh. but I was trying to make a complete algorithm. If I understand the procedure at once, I can write my code.
     
  4. Harald Kapp

    Harald Kapp Moderator Moderator

    11,313
    2,593
    Nov 17, 2011
    The algorithm is there in your list. Put it into a subroutine and simply call the subroutine from a timer interrupt every 10 ms.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-