help with shift register
iolas
Posts: 14
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
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
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
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
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.
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
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.
I will try and will inform..