User manual
655
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
Button
Prototype
function Button(var port: word; pin: byte; time: word; ActiveState: byte)
: word;
Description The function eliminates the inuence of contact ickering 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 - port: button port address
- pin: button pin
- time: debouncing period in milliseconds
- active_state: determines what is considered as active state. Valid values: 0 (logical zero) and
1 (logical one)
Returns -255 if the pin was in the active state for given period.
- 0 otherwise
Requires Nothing.
Example
program Button_Test;
var oldstate : bit;
begin
oldstate := 0;
ADPCFG := 0xFFFF; // initialize AN pins as
digital
TRISD := 0xFFFF; // initialize PORTD as
input
TRISB := 0x0000; // initialize PORTB as
output
while TRUE do
begin
if (Button(PORTD, 0, 1, 1)) then // detect logical
one on RB0 pin
oldstate := 1;
if (oldstate and Button(PORTD, 0, 1, 0)) then
begin // detect one-
to-zero transition on RB0 pin
LATB := not LATB;
oldstate := 0;
end;
end; // endless loop
end.
Notes None.