Button Library
The Button Library provides routines for detecting button presses and debouncing (eliminating the influence of contact flickering upon pressing a button).
Library Routines
Button
Prototype |
unsigned int Button(unsigned int *port, unsigned int pin, unsigned int time, unsigned int active_state); |
---|---|
Description |
The function eliminates the influence of contact flickering upon pressing a button (debouncing). The Button pin is tested just after the function call and then again after the debouncing period has expired. If the pin was in the active state in both cases then the function returns 255 (true). |
Parameters |
|
Returns |
|
Requires |
Nothing. |
Example |
if (Button(&PORTD, 0, 1, 1)) PORTB = 0xFF; ... |
Notes |
None. |
unsigned int oldstate; void main() { ADPCFG = 0xFFFF; // initialize AN pins as digital TRISD = 0xFFFF; // initialize portd as input TRISB = 0x0000; // initialize portb as output do { if (Button(&PORTD, 0, 1, 1)) // detect logical one state oldstate = 1; if (oldstate && Button(&PORTD, 0, 1, 0)) { // detect logical one to logical zero transition LATB = ~LATB; // toggle portb oldstate = 0; } } while(1); }
Copyright (c) 2002-2017 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
What do you think about this topic ? Send us feedback!