Shop OBEX P1 Docs P2 Docs Learn Events
Question on 74HC165 x 2 input switches - Stampworks Experiment 24 — Parallax Forums

Question on 74HC165 x 2 input switches - Stampworks Experiment 24

T&E EngineerT&E Engineer Posts: 1,396
edited 2006-01-01 16:23 in BASIC Stamp
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

Comments

  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2006-01-01 15:21
    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 WilliamsJon Williams Posts: 6,491
    edited 2006-01-01 16:22
    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, [noparse][[/noparse]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 WilliamsJon Williams Posts: 6,491
    edited 2006-01-01 16:23
    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
Sign In or Register to comment.