User`s manual
mikroBASIC
- Basic Compiler for Microchip PIC microcontrollers
166
mikroBASIC
MikroElektronika: Development tools - Books - Compilers
making it simple...
page
mikroBasic provides a set of procedures and functions for faster development of
your applications.
sub function Button(dim byref PORT as byte, dim PIN as byte,
dim Time as byte, dim Astate as byte) as byte
The Button function eliminates the influence of contact flickering due to the press-
ing of a button (debouncing).
Parameters PORT and PIN specify the location of the button; parameter Time rep-
resents the minimum time interval that pin must be in active state in order to
return one; parameter Astate can be only zero or one, and it specifies if button is
active on logical zero or logical one.
This code demonstrates use of library function Button. Example reads the state on
PORTB, pin 0, to which the button is connected. On transition from logical 1 to
logical 0 which corresponds to release of a button, value on PORTD is inverted.
program test
dim byref oldstate as byte
main:
PORTD = 255
TRISD = 0
TRISB = 255
while true
if Button(PORTB, 0, 1, 1) then
oldstate = 255
end if
if oldstate and Button(PORTB, 0, 1, 0) then
portD = 0
oldstate = 0
end if
wend
end.
Utilities
Example
Routines