Maker Pro
Maker Pro

Blink led at push of button

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
 

Harald Kapp

Moderator
Moderator
The algorithm is there in your list. Put it into a subroutine and simply call the subroutine from a timer interrupt every 10 ms.
 
Top