The first line reads two bytes ( 16 bits) into buttons
using MSBFIRST mode. The next line reverses the bits in
byte0 of buttons; bit0 and bit7 are swapped; bit1 and
bit6 are swapped, etc. Be a little careful with the reverse
operator; it clears unused bits to zero. In the above code,
we affected all the bits in buttons.byte0, so we’re fine. If
we wanted to flip the lower four bits of buttons, we
would have to do it like this:
At EFX-TEK, we were recently contracted to build a
controller for road signs. We used the '595 circuit as
shown to drive the gates of MOSFETs for the controller
outputs. The gate of each MOSFET was pulled low to
ensure the output would stay off until we wanted it to be
on ('595 outputs enable and high).
If you don't need to control the Output Enable,
remove the pull-up from that line and tie the OE pin(s) to
buttons := ins.read(ins#MSBFIRST, 2)
buttons := (buttons & $FFF0) |
(buttons.byte >< 4)
Operation of the '595 is a mirror of the '165. The
Propeller will place a bit on the serial input pin, then take
the clock high and back low to move that bit into the
'595 holding register. When all bits are shifted in, the
Latch line is pulsed high, then back low to transfer the
holding register to the outputs. The advantage of the
holding register is that outputs do not ripple as we're
shifting the data.
There is a nifty companion to the 74HC165 called
the 74HC595 that allows us to convert three (sometimes
four) I/O pins into eight outputs. Or 16. Or 24. Or even
32! Figure 2 illustrates the use of two 74HC595 chips to
create 16 digital outputs.
Let me point out that this is my "industrial" version.
Here, the Output Enable pins are pulled up to disable
In Figure 2, you can see that the serial output of the
first device is connected to the serial input of the second.
It's important to understand that the bits for the second
device are forced through the first device. When
cascading chips like this, we need to know how many
devices are in the chain to set the outputs correctly (of
course, this applies to the '165 as well).
(tri-state) the outputs from the '595s. This configuration
gives the Propeller plenty of time to boot up and preset
the outputs. By pulling the OE line low, the outputs will
go active. When using this configuration, you will want to
pull your '595 outputs to a known state.
Like the object for the '165, the code for the '595 is
super easy. There are, in fact, two more methods in this
one, but those are used to set and clear the Output
Enable line if it is used.
As before, the start() method takes the pins and
configures them for use:
pub start(dpin, cpin, lpin, epin)
longmove(@dout, @dpin, 4)
dira[dout] := 1
outa[clk] := 0
dira[clk] := 1
outa[latch] := 0
dira[latch] := 1
if (eout => 0)
outa[eout] := 1
dira[eout] := 1
After copying the pin numbers to global variables,
they are configured as outputs. The clock and latch line
are set up as output and low. If the Output Enable pin is
used, it is set up as an output and high to disable the
outputs from the '595s. If we don't have an Output
Enable line in the circuit, we pass -1 as the epin
■ FIGURE 2. 74HC595 outputs.
The write() method will move from one to four bytes
to a 74HC595 chain:
14 January 2014