Smart Star (how to use shift registers)


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Smart Star (how to use shift registers)

    A week or so ago my seven year old asked if we could make a new star for the tree this year.
    He has been playing with a Basic Stamp for the last few months and it looks like he will be getting his own PICKIT2 soon. I figured this would be a good time to introduce him to shift registers.

    The Smart Star was born.

    The 74HC595B was chosen. This is an 8 bit serial in parallel out register. The 595 has a serial out put that can be "daisy chained" to the serial input of the next one in line. This allows you to use only three pins from a PIC to control multiple out puts. In the case of the Smart Star, 40 LEDs are controlled.

    The way it works. 8 bits are sent to the first register in the chain with the SHIFTOUT command, the data sent will be in the first register. Then another 8 bits are sent. The data in the first register will be "pushed" out of the first register to the second register. Do this as many times as there are registers in the chain. When all of the data has been sent, a pulse is applied to the latching pin of each register. All of the latching pins are tied together.

    This all sounds like a slow process, but as you can see in the video it is surprisingly fast.



    Board layout.
    Solid lines are the bottom side of the board and the hollow lines are the top side.
    See attachment.
    The schematic is also attached

    The code could be optimised but a lot of it was written by a seven year old. He will get there
    Code:
    '16f676
    DEFINE OSC 4
    ASM
        ERRORLEVEL -306
        ERRORLEVEL -205
    ENDASM
    INCLUDE "modedefs.bas"
    @__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
    ANSEL=000000
    CMCON=7
    
    CLK    VAR    PORTA.4
    LATCH    VAR    PORTA.5
    DAT    VAR    PORTC.5
    U1  VAR BYTE
    U2  VAR BYTE
    U3  VAR BYTE
    U4  VAR BYTE
    U5  VAR BYTE
    A   VAR BYTE
    Y        VAR    BYTE
    Z        VAR    BYTE
    X        VAR    BYTE
    M        VAR    BYTE
    G   CON 010101
    R   CON 101010
    
    PAUSE 250
    
    START:
    FOR A = 1 TO 10
    U1 = 111111
    U2 = 111111
    U3 = 111111
    U4 = 111111
    U5 = 111111
    GOSUB BAR
    PAUSE 100
    U1 = 000000
    U2 = 000000
    U3 = 000000
    U4 = 000000
    U5 = 000000
    GOSUB BAR
    PAUSE 100
    NEXT A
    GOSUB LOOP
    GOSUB B1
    
    B1:
    FOR A = 1 TO 5
    U1 = 111111
    U2 = 000000
    U3 = 111111
    U4 = 111111
    U5 = 000000
    GOSUB BAR
    PAUSE 100
    U1 = 000000
    U2 = 000000
    U3 = 000000
    U4 = 000000
    U5 = 000000
    GOSUB BAR
    PAUSE 100
    NEXT A
    GOSUB LOOP
    GOSUB B2
    
    B2:
    FOR A = 1 TO 5
    U1 = 000000
    U2 = 111111
    U3 = 000000
    U4 = 000000
    U5 = 111111
    GOSUB BAR
    PAUSE 100
    U1 = 000000
    U2 = 000000
    U3 = 000000
    U4 = 000000
    U5 = 000000
    GOSUB BAR
    PAUSE 100
    NEXT A
    GOSUB LOOP
    GOSUB LOOP2
    
    LOOP:
    Z = 1
    FOR Y = 1 TO 8
    Z = Z * 2
    GOSUB BAR2
    PAUSE X
    NEXT Y
    X = X - 10
    IF X = 10 THEN X = 100
    'GOTO START
    RETURN
    
    LOOP2:
    FOR A = 1 TO 25
    Z = 1
    FOR Y = 1 TO 8
    Z = Z * 2
    GOSUB BAR2
    PAUSE X
    NEXT Y
    X = X - 10
    IF X = 10 THEN X = 100
    NEXT A
    GOSUB RG
    
    RG:
    FOR A = 1 TO 25
    U1 = R
    U2 = R
    U3 = R
    U4 = R
    U5 = R
    GOSUB BAR
    PAUSE 100
    U1 = G
    U2 = G
    U3 = G
    U4 = G
    U5 = G
    GOSUB BAR
    PAUSE 100
    NEXT A
    GOSUB LOOP
    GOSUB SPIR
    
    SPIR:
    X = 100
    FOR A = 1 TO 25
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[111111]
    PULSOUT LATCH,5
    PAUSE X
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[111111]
    SHIFTOUT DAT,CLK,1,[000000]
    PULSOUT LATCH,5
    PAUSE X
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[111111]
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[000000]
    PULSOUT LATCH,5
    PAUSE X
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[111111]
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[000000]
    PULSOUT LATCH,5
    PAUSE X
    SHIFTOUT DAT,CLK,1,[111111]
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[000000]
    SHIFTOUT DAT,CLK,1,[000000]
    PULSOUT LATCH,5
    PAUSE X
    X = X - 10
    IF X = 10 THEN X = 100
    NEXT A
    PAUSE 50
    GOTO START
    
    BAR:
    SHIFTOUT DAT,CLK,0,[U5]
    SHIFTOUT DAT,CLK,0,[U4]
    SHIFTOUT DAT,CLK,0,[U3]
    SHIFTOUT DAT,CLK,0,[U2]
    SHIFTOUT DAT,CLK,0,[U1]
    PULSOUT LATCH,5
    RETURN
    
    BAR2:
    SHIFTOUT DAT,CLK,0,[Z]
    SHIFTOUT DAT,CLK,0,[Z]
    SHIFTOUT DAT,CLK,0,[Z]
    SHIFTOUT DAT,CLK,0,[Z]
    SHIFTOUT DAT,CLK,0,[Z]
    PULSOUT LATCH,5
    RETURN
    
    END
    Attached Images Attached Images   
    Last edited by mackrackit; - 31st December 2011 at 00:16. Reason: fix html
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Thumbs up Nice work!

    A 7 year old! Wow, thats terrific. Tell him he did a great job for me!

    Steve B

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Dave, I like it! I think to build it for my christmas tree.

    Thank you for sharing the project.

    Al.
    All progress began with an idea

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by SteveB View Post
    A 7 year old! Wow, thats terrific. Tell him he did a great job for me!

    Steve B
    He said "Thank you"

    Quote Originally Posted by aratti View Post
    Dave, I like it! I think to build it for my christmas tree.

    Thank you for sharing the project.

    Al.
    Thanks,
    If I were to do another one I would use a PIC with a bit more memory. Maybe more LEDs, bigger, 3D version
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. LCD's with Shift Registers, and LCDOUT
    By Darrel Taylor in forum PBP Extensions
    Replies: 11
    Last Post: - 3rd April 2015, 15:34
  2. Use the PIC 16f877 or 877A instead of shift registers.
    By tsanders in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th October 2006, 18:23
  3. Shift Registers
    By shahidali55 in forum General
    Replies: 2
    Last Post: - 7th September 2006, 21:07
  4. Shift Registers For LCD Display
    By jetpr in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 7th July 2006, 16:03
  5. Replies: 15
    Last Post: - 30th January 2005, 04:58

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts