27297 Parallax Inc, 27297 Datasheet - Page 107

KIT STAMPWORKS WITH BS2-IC

27297

Manufacturer Part Number
27297
Description
KIT STAMPWORKS WITH BS2-IC
Manufacturer
Parallax Inc
Datasheet

Specifications of 27297

Lead Free Status
Contains lead
Product
Microcontroller Accessories
Lead Free Status / Rohs Status
Lead free / RoHS Compliant

Available stocks

Company
Part Number
Manufacturer
Quantity
Price
Part Number:
27297SQ
Manufacturer:
NS
Quantity:
4
Here’s the modified subroutine:
The real work is done by this line of code:
The current button state (nBtns) is compared with the previous scan value (oBtns)
using the Exclusive OR (^) operator. This will cause a bit to be ‘1’ when there is a
difference between the previous scan and the current. This [comparison] value is
then ANDed with nBtns which holds ‘1’ for each pressed button. The result is that
xBtns will have a ‘1’ for each button that was ‘0’ on the last scan and is ‘1’ on this
scan.
Note that if the button remains pressed and Get_Buttons is called again, the
respective bit of xBtns will change from ‘1’ to ‘0’ since there was no change of
button state.
See listing SW21-EX14-Debounce-Adv.BS2 for a full demonstration.
Take it Further
Modify the program to scan, debounce, and display eight buttons (Hint: Use INL or
INH).
Get_Buttons:
nBtns = %1111
FOR idx = 1 TO 5
NEXT
xBtns = nBtns ^ oBtns & nBtns
oBtns = nBtns
RETURN
xBtns = nBtns ^ oBtns & nBtns
nBtns = nBtns & ~BtnBus
PAUSE 5
' enable all four inputs
' test new inputs
' delay between tests
' look for 0 -> 1 changes
' save this scan
' look for 0 -> 1 changes

Related parts for 27297