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 : |
---|---|---|
var Button_Pin : sbit; bdata; sfr; external; |
Declares Button_Pin, which will be used by Button Library. | var Button_Pin: sbit at P0_0_bit; |
Library Routines
Button
Prototype |
function Button(time_ms : byte; active_state : byte) : 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_Test; // button connections var Button_Pin : sbit at P0_0_bit; // declare Button_Pin. It will be used by Button Library. // end Button connections oldstate : bit; begin P0 := 255; // configure PORT0 as input P2 := 0xAA; // initial PORT2 value while TRUE do begin if (Button(1, 1) <> 0) then // detect logical one oldstate := 1; // update flag if (oldstate and Button(1, 0)) then // detect one-to-zero transition begin P2 := not P2; // invert PORT2 oldstate := 0; // update flag end; end; // endless loop end. |
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!