Shop OBEX P1 Docs P2 Docs Learn Events
help with shift register — Parallax Forums

help with shift register

iolasiolas Posts: 14
edited 2008-10-02 00:36 in BASIC Stamp
hello
i have connect some buttons on a shift register 74hc165 and i want to make my basic stamp bsp40 to understand each of the Q1 Q2 Q3 Q4 Q5 Q6 Q7 seperately.

thanks roll.gif

Comments

  • ZootZoot Posts: 2,227
    edited 2008-09-30 18:16
    Do you have any code started (even if it doesn't work the way you want)? If so, can you post it? Can you give a clearer idea of what specifically you are trying to accomplish.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • iolasiolas Posts: 14
    edited 2008-09-30 21:09
    i want to make a project with many buttons and leds
    the problem is that i want to use many pins (more than 40 ) and thats why i use shift registers.
    As far i know one shift register can accept 7 buttons (inputs). i want to press one of the seven buttons and the basic stamp open a specific led.
    my program is below
    Clock PIN 0 ' shift clock (74HC165.2)
    SerData PIN 1 ' serial data (74HC165.7)
    Load PIN 2 ' output latch (74HC165.1)
    '
    [noparse][[/noparse] Constants ]
    DelayTime CON 100
    '
    [noparse][[/noparse] Variables ]

    D0 VAR Byte
    D1 VAR Byte
    D2 VAR Byte
    D3 VAR Byte
    D4 VAR Byte
    D7 VAR Byte
    D8 VAR Byte
    D9 VAR Byte
    D10 VAR Byte
    D11 VAR Byte
    '
    [noparse][[/noparse] Initialization ]
    vain:

    HIGH Load ' make output and high
    DO
    DEBUG CLS
    DEBUG ? D0
    DEBUG ? D1
    DEBUG ? D2
    DEBUG ? D3
    DEBUG ? D4
    DEBUG ? D7
    DEBUG ? D8
    DEBUG ? D9
    DEBUG ? D10
    DEBUG ? D11

    '
    [noparse][[/noparse] Program Code ]

    PAUSE DelayTime ' pad the loop a bit
    GOSUB Get_165 ' get switch inputs

    IF D0>=9 THEN

    high 12
    pause 250
    low 12

    '
    [noparse][[/noparse] Subroutines ]
    Get_165:
    PULSOUT load, 5 ' load switch inputs
    SHIFTIN SerData, Clock,MSBPRE, [noparse][[/noparse] D0,D1,D2,D3,D4,D7,D8,D9,D10,D11] ' shift them in
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-30 22:52
    It's much better to just shift the 12 bits into a 16 bit word variable, then access them individually.
    If you do a "SHIFTIN SerData,Clock,MSBPRE,[noparse][[/noparse]myWord]", you'll get 16 bits from the two 74HC165 cascaded 8-bit registers.
    You can then reference the individual bits by using BITn notation like "myWord.BIT3" to access bit #3 (of 0-15).
    "myWord" has to be defined as a word variable in this case.
  • ZootZoot Posts: 2,227
    edited 2008-09-30 22:54
    Does that code work? Seems like you're on the right track. Then it's a question of taking the variables that have received the shifted in data and moving them to LEDs. If you are doing one-to-one buttons to LEDs (12x8 buttons and 12x8 LEDs), then you will need shift registers or the like to run the LEDs. Then you could have your program turn right around and dump the variables back out.

    But if it's one-to-one then why not just wire each LED right to a button? Or are you doing other things with the LED output and buttons in?


    [noparse][[/noparse]edit] -- Just saw Mike's post.. is each byte a single bit (button)?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-01 00:05
    Zoot,
    Thanks. I was thinking that each byte variable represented a single bit from a button. It's not clear from the description. If each byte variable holds one shift register's worth of bits, then what I suggested won't work.

    By the way, you will need something after the "low 12" to stop the program, maybe a STOP statement. You'll also need a RETURN after the SHIFTIN so that "Get_165" will return to after the GOSUB.
  • iolasiolas Posts: 14
    edited 2008-10-02 00:36
    Thanks for your answers..
    I will try and will inform..
Sign In or Register to comment.