Before using this code you should read and understand this tutorial and this tutorial. This example combines those into a single example where the 74HC165 inputs are read and then sent out to a 74HC595. However this example shows how to reduce the number of I/O lines required by the microcontroller from 6 down to 4 by sharing the CLK and Data lines. In order to realize this please look at the attached schematic diagram. Note that the CLK lines are shared by both shift registers and connected to the same I/O pin on the Propeller chip. The data lines are shared too, but because they operate in different directions the data pin from the 74HC165 has a series 1K resistor. The LATCH and LOAD lines still require their own I/O pin but the total count is 4 instead of 6 and you could easily have 32 inputs and 32 outputs using these same 4 I/O pins. As you can see in the photo below I had to move a few wires on the PPDB and add the 1K resistor.
[IMAGE]In the previous combined example / demo no pins changes so the code was pretty easy to combine, however by sharing lines there is a consideration that requires us to make a simple code change to avoid conflicts on the I/O pins. The data lines connect to the Propeller chip P1, which needs to be an input to read from the 74HC165 but needs to be an output to write data to the 74HC595. So looking at the new code you’ll notice the PRI methods for each shift register have one additional line of code added.
In the writeHC595 method line 58 adds code to change the DATA pin to an output while in the readHC165 method line 73 adds code to change the DATA pin to an input. With these changes and the resistor on the 74HC165 data pin we can share the DATA line without any conflicts. If you’re wondering the reason why the resistor on on the 74HC165 data line and not the 74HC595 it’s because the 74HC595 data pin is an input, so there would never be a conflict with that pin no matter which direction the Propeller chip P1 pin in set to. The 74HC165 data pin is an output, so when the Propeller chip is writing data to the 74HC595 it would be fighting against the 74HC165 data pin. The resistor allows the 74HC165 to get data into the Propeller chip P1 when P1 is an input and is not affected by the 74HC595, while at the same time preventing contention when P1 is an output. Since P1 connects directly to the 74HC595 input pin the state of the 74HC165 pin won’t interfere. I hope you find this useful.
Oh, I wanted to add one thing…while the data changes depending on the state of the inputs, I did want to show you what one cycle of the CLK, LOAD and LATCH pins looks like. As you can see below the LOAD line starts the cycle by copying the data from the inputs into the 74HC165 internal shift register. The 8 clock pulses send this data serially into the Propeller DATA pin and then the data is sent serially out to the 74HC595 as indicated by the small delay and the next 8 clock pulses (remember, in this example both devices share the CLK and DATA lines). At this point the LATCH line is brought high storing the 8 bits from the 74HC595 shift register to the 8-bit parallel outputs, completing the cycle.
THIS ARTICLE IS STILL BEING RECOVERED AND RESTORED. PLEASE CHECK BACK LATER! Why is the article being recovered?
Resources
74HC165 Demo [SPIN] – Tutorial
74HC595 Demo [SPIN] – Tutorial
74HC165 to 74HC595 Demo 1 [SPIN] – Tutorial
Discuss this tutorial on Savage///Chats
Released under MIT License
Copyright (c) 2014 Chris Savage – Savage///Circuits.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
PLEASE FEEL FREE TO LEAVE YOUR COMMENTS, QUESTIONS, SUGGESTIONS OR FEEDBACK ON THIS POST.
Leave a Reply
You must be logged in to post a comment.