74hct595
Archiver
Posts: 46,084
How do I control a 74hct595 with my BS 1 or a PIC ??
Ren
Ren
Comments
Regards
Adrian
'{$STAMP BS2}
' Program: 74HC595.BS2 (Demonstrate 74HC595 shift register with
Shiftout)
' This program demonstrates the use of the 74HC595 shift register as
an
' 8-bit output port accessed via the Shiftout instruction. The '595
' requires a minimum of three inputs: data, shift clock, and latch
' clock. Shiftout automatically handles the data and shift clock,
' presenting data bits one at a time on the data pin, then pulsing the
' clock to shift them into the '595's shift register. An additional
' step--pulsing the latch-clock input--is required to move the shifted
' bits in parallel onto the output pins of the '595.
' Note that this application does not control the output-enable or
' reset lines of the '595. This means that before the Stamp first
' sends data to the '595, the '595's output latches are turned on and
' may contain random data. In critical applications, you may want to
' hold output-enable high (disabled) until the Stamp can take
control.
DataP CON 0 ' Data pin to 74HC595.
Clock CON 1 ' Shift clock to '595.
Latch CON 2 ' Moves data from shift register to output
latch.
counter VAR BYTE ' Counter for demo program.
' The loop below moves the 8-bit value of 'counter' onto the output
' lines of the '595, pauses, then increments counter and repeats.
' The data is shifted msb first so that the most-significant bit is
' shifted to the end of the shift register, pin QH, and the least-
' significant bit is shifted to QA. Changing 'msbfirst' to 'lsbfirst'
' causes the data to appear backwards on the outputs of the '595.
' Note that the number of bits is _not_ specified after the variable
' in the instruction, since it's eight, the default.
'counter = 3
Again:
ShiftOut DataP,Clock,msbfirst,[noparse][[/noparse]counter] ' Send the bits.
PulsOut Latch,1 ' Transfer to
outputs.
Pause 500 ' Wait briefly.
counter = counter+1 ' Increment counter.
GoTo Again ' Do it again.
PIC) or microprocessor (8088-468-Pentium) should do.
--- In basicstamps@yahoogroups.com, Ren
I used this before but I want to use the BS1 or a PIC to get the cost down.
I found this but i can't get it right.
Simulate BS2 Shiftin and Shiftout
Symbol DDIR = Dir0 ' Shift data pin direction is Dir0
Symbol DPIN = Pin0 ' Shift data pin is 0
Symbol CPIN = 1 ' Shift clock pin is 1
Symbol I = B2 ' Loop counter
' Shift in some data
Low CPIN ' Start shift clock low
GoSub shiftin ' Shift in some data
' Shift out some data
Low CPIN ' Start shift clock low
B0 = 100 ' Data to shift out
GoSub shiftout ' Go do it
End
' Subroutine to synchronously shift in one byte
shiftin: DDIR = 0 ' Set data pin direction to input
For I = 1 to 8 ' 8 bits to a byte
B0 = B0 * 2 ' Shift result 1 bit to the left
Toggle CPIN ' Toggle shift clock
Bit0 = DPIN ' Move data into LSB
Toggle CPIN ' Toggle shift clock once more
Next I ' Loop
Return ' Go back to caller
' Subroutine to synchronously shift out one byte
shiftout: DDIR = 1 ' Set data pin direction to output
For I = 1 to 8 ' 8 bits to a byte
DPIN = Bit0 ' Data out is LSB
Toggle CPIN ' Toggle shift clock
B0 = B0 / 2 ' Shift byte 1 bit to the right
Toggle CPIN ' Toggle shift clock once more
Next I ' Loop
Return ' Go back to caller
Where in tihs is my LOAD command ???
Ren
The SEROUT/SERIN commands are for UART type signals --
they have a specified BAUD rate, which the '595 knows
nothing about.
And, the BS1 does not have the SHIFTIN/SHIFTOUT commands,
which the BS2 would use to control a '595.
So, you have to emulate the SHIFTIN/SHIFTOUT commands in
the BS1 to use the '595.
' BS1 Code (Shiftout.BAS)
BSAVE ' Make Code.OBJ of this.
Symbol SerData = 0 ' SerData Pin
SYMBOL SerClk = 1 ' SerClk Pin
Symbol DataByte = B0 ' Zeroth Reg Byte
Symbol Temp = B1 ' First Reg Byte
LOW SerData
LOW SerClk
MainLoop:
DataByte = $0F ' Or whatever you want...
GOSUB SendByte
GOTO MainLoop
SendByte:
FOR Temp = 1 to 8
IF Bit0 = 1 THEN OutputOne ' Bit0..7 Are B0 bits...
' ELSE
GOTO OutputZero
OutputOne:
HIGH SerData
GOTO ForNext
OutputZero:
LOW SerData
ForNext:
Pulsout SerClk, 1
DataByte = DataByte / 2 ' Shift Down
Next
RETURN
--- In basicstamps@yahoogroups.com, "Dave Mucha" <davemucha@j...>
wrote:
> isn't it with any serial instructions ? micro contorller (BS1 or
> PIC) or microprocessor (8088-468-Pentium) should do.
>
>
>
> --- In basicstamps@yahoogroups.com, Ren
The 74HCT595 is a Serial In (from Stamp) to
Parallel OUT (to the world) chip. It is
to send bits out to the world -- you can't
read its parallel pins back into the Stamp.
The 74hct165 is a Parallel In (From World) to
Serial Out (To Stamp). You use this chip
to read parallel data from the world into
the stamp -- interfacing is similar.
See the Phillips website, which has PDF
documents of both chips for more detail.
--- In basicstamps@yahoogroups.com, Ren
The BS1 is awfully limited in terms of pins,
and speed, especially compared to a PIC.
Still, the principle applies:
To output, set the Data bit, pulse the Clock bit,
set the next Data Bit .. repeat 8 times per byte.
To Input (from a '165), set the Data bit as input,
Pulse the clock bit, read the first data bit,
pulse the clock bit, read the next data bit,
.. repeat 8 times per input byte.
--- In basicstamps@yahoogroups.com, "Allan Lane" <allan.lane@h...>
wrote:
> Hello again.
> The 74HCT595 is a Serial In (from Stamp) to
> Parallel OUT (to the world) chip. It is
> to send bits out to the world -- you can't
> read its parallel pins back into the Stamp.
>
> The 74hct165 is a Parallel In (From World) to
> Serial Out (To Stamp). You use this chip
> to read parallel data from the world into
> the stamp -- interfacing is similar.
>
> See the Phillips website, which has PDF
> documents of both chips for more detail.
>
> --- In basicstamps@yahoogroups.com, Ren