Snippet Needed For 74HC165 Three Pin Hookup
idbruce
Posts: 6,197
Hello Everyone
I am searching for a 74HC165 snippet for a three IO pin hookup. The OBEX has an object, but it utilizes four pins. Any input would be appreciated.
Bruce
I am searching for a 74HC165 snippet for a three IO pin hookup. The OBEX has an object, but it utilizes four pins. Any input would be appreciated.
Bruce
Comments
http://nutsvolts.texterity.com/nutsvolts/201005/?pg=17#pg17
EDITED: Here is a much better link to the solution
http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp6.pdf
While reading the input from this shift register, I will be shifting 8 bits into a global variable, during which time only 1 of the 8 available inputs will be valid.
Can I test for valid input with the following conditions?
to use ( for getting a button pressed)
vButtonPressed := Shift.In(InputLoadPin, InputDataPin, InputClockPin, InputBits)
Use the case statement for checking against the button values INSTEAD of the multiple if statements
regards
Dave M
Was my assumption was correct, that I could take those bits (as a byte) and compare it to the decimal values stated? I am assuming that I can, because your reply contains the same values.
Bruce
128 == $80 == %1000_0000
The Propeller IDE doesn't care which format you use. For binary inputs like you're using, I tend to use binary formatting. Had I written the code I would have done this:
My original point is that case is easier to follow (and probably generates the same amount of code).
I definitely appreciate it.
Bruce
I missed half of that when I first read it. That is definitely a whole neater than a bunch of IF's, and I guess a binary comparison makes a lot more sense also. Thanks again Jon.
Bruce
PS Did you use my Shift register code? It uses 3 pins ( as you were asking for)
regards
Dave M
I really like your constant idea for the buttons, I will use that idea. As for the shift register, I used Jon's code, because your code was using an extra variable for the individual bits. Additionally, it looks as though your 595 code uses four pins. For a 595, here is what I use:
But I do appreciate your effort and code. Thank you David.
Bruce
Hi Bruce,
If you use more than 1 shift register you need define the no of bits to get from the device's. It's usually 8bits per chip.
I use many shift registers daisy chained together, and on some of my boards I use multiple sets, So By using the ONE very simple Object, you can refer to ( use) and no of devices, Just put 8 in the place of the variable.
I do encourage you to use more GENERIC CODE, It looks like that code is for a specific purpose. Also I can't see the PIN Definitions for the shift register?
Also, ALWAY use CONSTANTS for ALL your pin definitions and any other hardware, such as buttons. leds, modes etc,It makes coding much more READABLE, RELIABLE & REUSABLE, as you only need to change the value of a constant ONCE, especially if you use that constant in more than one place.
One other thing, regarding constants, Did you notice the use of "Input", "Output", "High" , "Low" etc, I Alway do this for ALL My projects, and all my objects, So that I can easily read these states in my code, much better than 1, 0, ~, ~~ etc
regards
Dave M
I must say that all makes perfect sense. It sounds like you have a good head on your shoulders for programming microcontrollers
Over the last several months, I have been using constants a lot more than in the past, and I imagine that I will continue in that direction. However, I must say that I am also becoming accustomed to seeing and quickly understanding the ~ and ~~. In the past, I used HIGH and LOW, but I found that I save coding time by using the symbols instead.
I definitely need to start incorporating case statements in my code, because it is easier to write and read. Considering I started with no knowledge of Spin when I began this current major programming endeavor, all of my code needs to go through the refining and beautification processes
Anyhow, thanks for your advice David.
Bruce
P.S. Jon keeps telling me the same thing However, in my defense, that code was written over two years ago, and yes it was application specific. That code was for controlling a stepper motor with a 595, which has since been replaced with a Gecko G251 Stepper Driver.