27220 Parallax Inc, 27220 Datasheet - Page 107

BOOK STAMPWORKS

27220

Manufacturer Part Number
27220
Description
BOOK STAMPWORKS
Manufacturer
Parallax Inc
Datasheet

Specifications of 27220

Accessory Type
Booklet
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
StampWorks
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Not applicable / Not applicable
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 27220