Pic microcontroller button press code activation?

I've just recently started with Pic microcontrollers. I actually have made some pretty cool projects with leds and a few other things that i will probably upload. Right now Im working with a pic 16F628A, I want a command to start only if a button is pressed. Ive tried a few different variations ive seen online but none of them have worked.  Could you please post the pins of the button and add the code to the code below.
Written in C

 void send_sync (void){

printf("\r\nSending Sync command: ");
print_cmd(sync_cmd);
send_data(sync_cmd);
delay_ms(50);
printf("\r\nSYNC command sent\r\n> .");

}

iceng4 years ago
I have used  thsi word flow-chart to excellent key de-bounce :

  1. TEST KEY PIN ( looking for low PRESSED  Key )
  2. IF KEY IS HIGH
  3.    PAUSE 100 ms
  4.    GOTO  Step 1.TEST KEY
  5. IF KEY IS LOW
  6.    PAUSE 100 ms
  7. TEST KEY PIN ( again )
  8. IF KEY IS HIGH
  9.    GOTO  Step 1. reTEST KEY
  10. NOW THE KEY PIN IS LOW DEPRESSED !
  11. nop
  12. DO LOW KEY PRESSED SWITCH ROUTINES HERE
  13. nop
  14. TEST KEY PIN ( looking for HIGH RELEASED )
  15. IF KEY IS LOW
  16.    PAUSE 100 ms
  17.    GOTO  Step 14. reTEST KEY
  18. IF KEY IS HIGH
  19.    PAUSE 100 ms
  20. TEST KEY PIN ( again )
  21. IF KEY IS LOW
  22. GOTO  Step 14 .TEST KEY
  23. NOW THE KEY PIN IS HIGH !
  24. DO HIGH KEY RELEASED SWITCH ROUTINES HERE
  25. BRANCH WHEN NEEDED  :-)

A
Slllllooooowwwwwww. I aim to recognise the key in less than 100mSec tops, otherwise the user feels the delay.
If the OP gets this going, Then an ISR ( interrupt service routine ) can
be set to react to a pin change and prep a jump through a lookup table.
That would be several bits faster :-)
Much as a I loathe the PIC, for technical reasons, I have to admit that I found this clever technique, the vertical counter, described here http://www.dattalo.com/technical/software/pic/vertcnt.html


is an excellent method of doing very compact debouncing algorithms. Of course, I rewrote it in the 8052 Here