PDA

View Full Version : Question on 74HC165 x 2 input switches - Stampworks Experiment 24



T&E Engineer
12-31-2005, 07:38 AM
Refering to the Stampworks experiment 24 with the 74HC165 cascaded input circuit....

The input switches provide (2) Byte (or 1 Word) but in this case I modified it for (2) Bytes for each 8 input switches.

Everything said it is working correctly.

My question is that I want to be able to "capture" or "latch in" 3 pushbutton sequences and store it probably as 3 separate bytes.

I'm not sure what approach to try such as polling or something else??


In other words, I press the 3rd pushbutton and I want to store the binary code %00000011 in a Byte such as "Digit100s". Then the second time I hit another pushbutton (lets say the 5th pushbutton) I want to store the binary code %00000101 in a Byte such as "Digit10s". Finally the 3rd time I press on a pushbutton (lets say the 8th pushbutton) I want to store the binary code %00001000 in a Byte such as "Digit1s".

Does anyone have experience with something like this?

If I think about it long enough I can come up with something. However, I am a believer in not re-inventing the wheel. To gain knowledge to learn from is the first step in sharing it for those in need.

I would appreciate any comments.

Thanks,

Timothy Gilmore

T&E Engineer
01-01-2006, 11:21 PM
Here is what I came up with if anyone is interested:

(It doesn't use the 74HC165 as I was not able to get that working right)

================================================== ===

' ButtonTest.BS2
' Written by Timothy Gilmore
' December 31st, 2005


' {$STAMP BS2}
' {$PBASIC 2.5}

Btn0ˇˇˇˇˇˇˇˇˇˇˇ PINˇˇˇˇ 0
Btn1ˇˇˇˇˇˇˇˇˇˇˇ PINˇˇˇˇ 1
Btn2ˇˇˇˇˇˇˇˇˇˇˇ PINˇˇˇˇ 2
Btn3ˇˇˇˇˇˇˇˇˇˇˇ PINˇˇˇˇ 3
Btn4ˇˇˇˇˇˇˇˇˇˇˇ PINˇˇˇˇ 4
Btn5ˇˇˇˇˇˇˇˇˇˇˇ PINˇˇˇˇ 5
Btn6ˇˇˇˇˇˇˇˇˇˇˇ PINˇˇˇˇ 6
Btn7ˇˇˇˇˇˇˇˇˇˇˇ PINˇˇˇˇ 7
Btn8ˇˇˇˇˇˇˇˇˇˇˇ PINˇˇˇˇ 8
Btn9ˇˇˇˇˇˇˇˇˇˇˇ PINˇˇˇˇ 9

' ---------------------------------------------------------------------
' Constants
' ---------------------------------------------------------------------


' ---------------------------------------------------------------------
' Variables
' ---------------------------------------------------------------------

btnWrk0ˇˇˇˇˇˇˇˇ VARˇˇˇˇ Byte
btnWrk1ˇˇˇˇˇˇˇˇ VARˇˇˇˇ Byte
btnWrk2ˇˇˇˇˇˇˇˇ VARˇˇˇˇ Byte
btnWrk3ˇˇˇˇˇˇˇˇ VARˇˇˇˇ Byte
btnWrk4ˇˇˇˇˇˇˇˇ VARˇˇˇˇ Byte
btnWrk5ˇˇˇˇˇˇˇˇ VARˇˇˇˇ Byte
btnWrk6ˇˇˇˇˇˇˇˇ VARˇˇˇˇ Byte
btnWrk7ˇˇˇˇˇˇˇˇ VARˇˇˇˇ Byte
btnWrk8ˇˇˇˇˇˇˇˇ VARˇˇˇˇ Byte
btnWrk9ˇˇˇˇˇˇˇˇ VARˇˇˇˇ Byte

Valueˇˇˇˇˇˇˇˇˇˇˇˇ VARˇˇˇˇ Byte
Digit100sˇˇˇˇˇˇˇˇVARˇˇˇˇ Byte
Digit10sˇˇˇˇˇˇˇˇˇ VARˇˇˇˇ Byte
Digit1sˇˇˇˇˇˇˇˇˇˇˇ VARˇˇˇˇ Byte
Totalˇˇˇˇˇˇˇˇˇˇˇˇˇ VARˇˇˇˇ Byte

' ---------------------------------------------------------------------
' Initialization
' ---------------------------------------------------------------------

Initialize:

' ---------------------------------------------------------------------
' Program Code
' ---------------------------------------------------------------------

Main:

GOSUB Get3Buttonsˇˇˇˇˇˇˇ 'Get allˇ3 digits from pushbuttons

DEBUG DEC Digit100s ˇˇˇˇ 'Display in DEBUG window 100's digit
DEBUG DEC Digit10s
DEBUG DEC Digit1s

Total = (Digit100s * 100) + (Digit10s * 10) + Digit1sˇˇˇˇˇˇ'Add them up

' More code here ....




DEBUG CLRDN, CRˇˇˇˇˇˇˇˇˇ 'Clear the DEBUG window for next 3 digits to be displayed

GOTO Mainˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇ 'Repeat process

' ---------------------------------------------------------------------
' Subroutines
' ---------------------------------------------------------------------

Get3Buttons:
ˇValue = 255
ˇGOSUB GetButtons
ˇDigit100s = Value
ˇValue = 255
ˇGOSUB GetButtons
ˇDigit10s = Value
ˇValue = 255
ˇGOSUB GetButtons
ˇDigit1s = Value
ˇRETURN


GetButtons:
Button0:
ˇ PAUSE 5
ˇ BUTTON Btn0, 0, 200, 20, btnWrk0, 0, Button1
ˇ Value = 0

Button1:
ˇ PAUSE 5
ˇ BUTTON Btn1, 0, 200, 20, btnWrk1, 0, Button2
ˇ Value = 1

BUTTON2:
ˇ PAUSE 5
ˇ BUTTON Btn2, 0, 200, 20, btnWrk2, 0, Button3
ˇ Value = 2

BUTTON3:
ˇ PAUSE 5
ˇ BUTTON Btn3, 0, 200, 20, btnWrk3, 0, Button4
ˇ Value = 3

BUTTON4:
ˇ PAUSE 5
ˇ BUTTON Btn4, 0, 200, 20, btnWrk4, 0, Button5
ˇ Value = 4

BUTTON5:
ˇ PAUSE 5
ˇ BUTTON Btn5, 0, 200, 20, btnWrk5, 0, Button6
ˇ Value = 5

BUTTON6:
ˇ PAUSE 5
ˇ BUTTON Btn6, 0, 200, 20, btnWrk6, 0, Button7
ˇ Value = 6

BUTTON7:
ˇ PAUSE 5
ˇ BUTTON Btn7, 0, 200, 20, btnWrk7, 0, Button8
ˇ Value = 7

BUTTON8:
ˇ PAUSE 5
ˇ BUTTON Btn8, 0, 200, 20, btnWrk8, 0, Button9
ˇ Value = 8

BUTTON9:
ˇ PAUSE 5
ˇ BUTTON Btn9, 0, 200, 20, btnWrk9, 0, No_Press
ˇ Value = 9


No_Press:
IF Value = 255 THEN
ˇ GOTO Button0
ENDIF
RETURN

================================================== ====

Jon Williams
01-02-2006, 12:22 AM
If you're looking to capture 24 inputs with the '165 it's simply a matter of daisy-chaining a third chip -- then you would update the scan routine as follows:

Get_XInputs:
ˇ PULSOUT Load, 5
ˇ SHIFTIN SerData, Clock, MSBPRE, [xIn1, xIn2, xIn3]
ˇ RETURN

... where xIn1, xIn2, and xIn3 are defined as bytes; xIn1 is the 74x165 connected first in the chain (relative to the BASIC Stamp).

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Jon Williams
01-02-2006, 12:23 AM
Another note: Using multiple instances of BUTTON is not very efficient; StampWorks experiment #14 demonstrates how to simultaneously debounce and scan mutliple inputs.ˇ I use the Get_Buttons subroutines in a lot of my programs as it's easy to expand -- the target variable can be a Nib (1 to 4 inputs), Byte (up to 8 inputs) or Word (up to 16 inputs).ˇ It's quite flexible and with bit-level aliasing of the input variable can make one's program very easy to work with.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax