Button Library
Button library contains miscellaneous routines useful for project development.
External dependecies of Button Library
The following variable must be defined in all projects using Button library: | Description: | Example : |
---|---|---|
dim Button_Pin as sbit external |
Declares Button_Pin, which will be used by Button Library. | dim Button_Pin as sbit at P0_0 |
Library Routines
Button
Prototype |
sub function Button(dim time_ms as byte, dim active_state as byte) as byte |
---|---|
Returns |
|
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 :
|
Requires |
Button pin must be configured as input. |
Example |
P2 is inverted on every P0.B0 one-to-zero transition : program Button ' Button connections dim Button_Pin as sbit at P0.B0; ' Declare Button_Pin. It will be used by Button Library. ' End Button connections bit oldstate; ' Old state flag main: P0 = 255 ' Configure PORT0 as input P2 = 0xAA ' Initial PORT2 value do { if (Button(1, 1)) ' Detect logical one oldstate = 1; ' Update flag if (oldstate && Button(1, 0)) { ' Detect one-to-zero transition P2 = ~P2; ' Invert PORT2 oldstate = 0; ' Update flag } } while(1); ' Endless loop }'~! |
Copyright (c) 2002-2013 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
What do you think about this topic ? Send us feedback!