PDA

View Full Version : help with shift register



iolas
09-30-2008, 06:39 PM
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 http://forums.parallax.com/images/smilies/roll.gif

Zoot
10-01-2008, 01:16 AM
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 (http://1uffakind.com/robots/povBitMapBuilder.php)
1uffakind.com/robots/resistorLadder.php (http://1uffakind.com/robots/resistorLadder.php)

iolas
10-01-2008, 04:09 AM
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)
' -----[ Constants ]-------------------------------------------------------
DelayTime CON 100
' -----[ 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
' -----[ 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

' -----[ 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

' -----[ Subroutines ]-----------------------------------------------------
Get_165:
PULSOUT load, 5 ' load switch inputs
SHIFTIN SerData, Clock,MSBPRE, [ D0,D1,D2,D3,D4,D7,D8,D9,D10,D11] ' shift them in

Mike Green
10-01-2008, 05:52 AM
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,[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.

Zoot
10-01-2008, 05:54 AM
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?


[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 (http://1uffakind.com/robots/povBitMapBuilder.php)
1uffakind.com/robots/resistorLadder.php (http://1uffakind.com/robots/resistorLadder.php)

Mike Green
10-01-2008, 07:05 AM
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.

iolas
10-02-2008, 07:36 AM
Thanks for your answers..
I will try and will inform..