Shop OBEX P1 Docs P2 Docs Learn Events
74HC595 High all Ports — Parallax Forums

74HC595 High all Ports

PlayLikeFabianPlayLikeFabian Posts: 8
edited 2017-03-30 14:57 in BASIC Stamp
Hey all,
I recently bought a BS1 'cause I wanna build kind of an 'orientation system' for blind people. For this project I need more than 8 ports, so I ordered the 74HC595.
I'm not that into programming the BS1 and I already know, that I need to reset SHIFTIN and SHIFTOUT.
So I only need outputs, because I can easily connect the inputs to my usual ports. Imagine if I wanted to high every single port by the shift register. I already did some research but I'm not really sure, how to do it properly.
I would be fine, if you only showed me, how to set the shift-ports high, that I want to have high.

Here's my code so far:
' {$STAMP BS1}
OUTPUT 1
OUTPUT 2
OUTPUT 3

start:
B0=%00000000
GOSUB ShiftOut
PAUSE 500

'OnOff:
B0=%11111111
DEBUG CLS, "on"
GOSUB ShiftOut
PAUSE 1000
B0=%00000000
DEBUG CLS, "off"
GOSUB ShiftOut
PAUSE 1000
'GOTO OnOff

END

ShiftOut:
  FOR B11=1 TO 8
    PIN0=BIT7
   PULSOUT 1, 1
    B0=B0*2
   NEXT
 PULSOUT 2, 1
  RETURN

So tbh, even yet it's not working. I just wanted to turn the ports of my shift register on and off again. Any help or at least tried help would be appreciated so much.

Thanks,
PlayLikeFabian

Comments

  • Take a look at page 130 of the Stamp Works pdf (big file).

    Page 130 if page 140 of the pdf.
  • kwinnkwinn Posts: 8,697
    FYI, the BS1 does not have a shiftin or shiftout instruction so you will have to output the signals to the 74HC595 one bit at a time. Not difficult to do though. Do you know how to connect the BS1 to the 74HC595?
  • tomcrawfordtomcrawford Posts: 1,129
    edited 2017-03-30 18:16
    So I'm thinking you have these connections ('595 pins are for DIP)
    BS1 pin 1   '595 pin 14 SER
    BS1 pin 2   '595 pin 11 SCLK
    BS1 pin 3   '595 pin 12 RCLK
    

    Do you have '595 pin 13 OE grounded?
    Do you have '595 pin 10 SRCLR pulled high?

    Your code looks good to me. What happens when you run it?

    Edit: The above list is incorrect. It should be
    BS1 pin 0   '595 pin 14 SER
    BS1 pin 1   '595 pin 11 SCLK
    BS1 pin 2   '595 pin 12 RCLK
    
  • kwinn wrote: »
    FYI, the BS1 does not have a shiftin or shiftout instruction so you will have to output the signals to the 74HC595 one bit at a time. Not difficult to do though. Do you know how to connect the BS1 to the 74HC595?

    Looks like he wrote a subroutine called "shiftout"


  • kwinnkwinn Posts: 8,697
    Publison wrote: »
    kwinn wrote: »
    FYI, the BS1 does not have a shiftin or shiftout instruction so you will have to output the signals to the 74HC595 one bit at a time. Not difficult to do though. Do you know how to connect the BS1 to the 74HC595?

    Looks like he wrote a subroutine called "shiftout"


    Now I'm wondering if I was having a seniors moment or the code was edited between looking at it and composing a reply.
  • kwinn wrote: »
    Publison wrote: »
    kwinn wrote: »
    FYI, the BS1 does not have a shiftin or shiftout instruction so you will have to output the signals to the 74HC595 one bit at a time. Not difficult to do though. Do you know how to connect the BS1 to the 74HC595?

    Looks like he wrote a subroutine called "shiftout"


    Now I'm wondering if I was having a seniors moment or the code was edited between looking at it and composing a reply.

    Yes I edited it from "spoiler" to "code" so it would be more readable.
  • BTW,

    Welcome to the forum!

    We will try and find a solution.
  • First of all: Thanks to all these fast answers, didn't expect some so soon.
    Publison wrote: »
    Welcome to the forum!
    Thank you very much. I appreciate it :D

    @Duane Degn
    Setup looks quite fine to me. Should be the code I'm struggling with.


    Your code looks good to me. What happens when you run it?
    My LEDs just turn on and stay on forever. I only wanted it to stay turned on for 1 second.
    I don't quite get the things about PIN13 OE and the other line to be honest. Sorry about me being that dumb, but I'm new to all of this.
  • On the '595, you have to ground OE, and pull SRCLR high.

    By LEDs, I am thinking you have LEDs with series resistors to ground on each Q.
  • You are counting pins on the BS1 oddly.

    You enable pins 1, 2, and 3 at the beginning and then use pins 0, 1, 2 in your shift routine.

    In the beginning,
    Output 0
    Output 1
    Output 2
    

    or better still
    DIRS = %00000111
    
  • Output 0
    Output 1
    Output 2
    

    or better still
    DIRS = %00000111
    
    Did it, still not working .__.
  • Sorry you're having trouble. What you need to do now is show us exactly what you are doing. Post a photo that clearly shows your wiring and post the exact code you are using. I am attaching mine here as an example as well as a logic analyzer capture. I removed the logic analyzer probes as well as connections to eight LEDs to more clearly show the shift register wiring.
    I promise we can help you to make this work.
    ' {$STAMP BS1}
    
    begin:
    DIRS = %00000111   'enable the control outputs
    
    B0 = 0             'initialize the shift register
    GOSUB shiftout
    PAUSE 100
    
    top:               'loop here forever
    B0 = B2            'get new value to display
    GOSUB shiftout     'send it to shift register
    B2 = B2 + 1        'calculate new value to next pass
    PAUSE 100          'a little delay
    GOTO top           'forever
    
    END
    
    shiftout:
    FOR B1 = 1 TO 8    'will do eight bits
      PIN0 = BIT7      'current bit (MSB first)
      PULSOUT 1,1      'clock pulse
      B0 = B0 + B0     'left shift (timy bit faster than multiply)
      NEXT             'eight times
    PIN0 = 0           'not needful, looks better on logic analyzer
    PULSOUT 2, 1       'move result into display register
    RETURN             'exit
    
    2048 x 1536 - 642K
    1202 x 690 - 70K
  • Well I'm basically just confused. I will add a photo of what I plugged to make it work. My LEDs usually are plugged in on the 'left' side of the board. I exactly copied @tomcrawford 's code and now I'm even more confused how to get that loop included in my program.
    484 x 741 - 649K
  • Now *I* am confused. It looks to me like P0 is connected to '595 pin 12 and P2 is connected to '595 pin 14, which would be swapped from what I did. And yet you say it worked.

    Also, I'm not sure what you mean when you are confused how to get that loop included in my program. Copy and paste?


  • Well, Obviously a randomly spinning loop is not my goal for my project. I only want some ports to be high when I need them to.
    And it didn't really work, so maybe I have to swap them too.
    Maybe my understanding of a shift register isn't what it should be. I now don't really get the function.
  • The way the program is written, it definitely expects the shift register serial data in (SER: pin 14) to be connected to P0 and Storage Register Clock (RCLK: pin 12) to be connected to P2. If they are not connected that way it simply won't work.

    The '595 (data sheet is here) is a little more than a simple shift register; it also contains a storage register. That way the parallel outputs don't change more or less randomly while the shifter is being loaded. The FOR/NEXT loop loads eight bits, one at a time, into the shift register. The PULSOUT 2,1 provides a positive edge that loads the storage register and thence the outputs.

    I programmed a simple counter only so I could observe the outputs (connected to LEDs) and thus convince myself that the setup was working.
  • So it basically is possible to write any program, define the used outputs and just use them by gosubbing to shiftout?
  • tomcrawfordtomcrawford Posts: 1,129
    edited 2017-04-06 17:44
    Shiftout will load the contents of B0 into the shift register. A side effect is that it will destroy the contents of B0 (it will be left 0) and B1 (it will be left 8 ).

    You could call shiftout a "driver". My little program that incremented B2 could be called a test program or demo.
  • So I still don't get it right. I'll just explain to you, what I'm trying to do: I wanna have kind of a orientation system for blind people with 3 ultrasonic detectors(?) and 3 speakers. Each detector should send a signal to one of the speakers, so the blind person is able to coordinate his walking. I need more than 8 ports so I need the shift register. Does this help you 'cause I'm literally stuck
  • Q1: Does your shift register work? Are you able to send an arbitrary value to SHIFTOUT and observe the expected results at the '595 outputs?
    A1Y: If so, what is your real question? Do you want help in connecting the sensors and speakers?
    A1N (Q2): If not, did you make the changes to P0 and P2 I pointed out?
    A2Y: If so, show me. Post a photo of your board that clearly and unambiguously shows the connections along with the code.
    A2N: If not, why not.

    Q3: If you are using Ping sensors, they need one I/O each. That is three, plus three for the speakers for a total of six. A BS-1 has eight I/Os. Are you sure you need an expander in the first place?
  • I just had a look at the specifications for the BS-1 Project Board. It supplies only 40 mA for the project. If you have eight LEDs pulling 10 mA each, that is 80 mA right there. Please be sure you are not overloading the regulator. That might explain a lot.
  • Ok, it's done. Had some failure with the cable management and messed up with the ports 1 and 2. Took me over 1 month but finally it's working. Thanks for your affort all :)
Sign In or Register to comment.