Util library, Mikroc, Button – ABL electronic PIC Microcontrollers PIC16 User Manual

Page 288

Advertising
background image

Util library contains miscellaneous routines useful for project development.

mikroC - C Compiler for Microchip PIC microcontrollers

mikroC

making it simple...

280

MikroElektronika: Development tools - Books - Compilers

page

Util Library

Prototype

char

Button(char *port, char pin, char time, char active_state);

Returns

Returns 0 or 255.

Description

Function eliminates the influence of contact flickering upon pressing a button (debounc-
ing).

Parameters

port

and

pin

specify location of the button; parameter

time

specifies the

minimum time pin has to be in active state in order to return TRUE; parameter

active_state

can be either 0 or 1, and it determines if button is active upon logical

zero or logical one.

Example

Example reads RB0, to which the button is connected; on transition from 1 to 0 (release
of button), PORTD is inverted:

do

{

if

(Button(&PORTB, 0, 1, 1)) oldstate = 1;

if

(oldstate && Button(&PORTB, 0, 1, 0)) {

PORTD = ~PORTD;

oldstate = 0;

}

} while(1);

Button

Advertising
This manual is related to the following products: