Newbie 74hc595 question


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2008
    Posts
    5

    Default Newbie 74hc595 question

    Hie
    I'm a newbie in pic programming and i'm trying to build a night lamp with 30 leds. at start they are all supposed to be lit and then after every minute one of them should turn off.
    I built the circuit using 4 74hc595 cascaded and with a pic16f684 i had laying around with a 4 MHZ xtal.
    my question is about the code - if i understand correctly, the code it should look like this:

    Include "modedefs.bas" ' Include shift modes

    D1PIN var PORTA.0 ' Shift data pin 1
    C1PIN var PORTA.1 ' Shift clock pin 1

    bvar var BYTE

    bvar = 255
    ' Shift out 8 bits of data onto other pins
    Shiftout D1PIN, C1PIN, MSBFIRST,[bvar]
    Shiftout D1PIN, C1PIN, MSBFIRST,[bvar]
    Shiftout D1PIN, C1PIN, MSBFIRST,[bvar]
    Shiftout D1PIN, C1PIN, MSBFIRST,[bvar]

    Main:
    sleep 1000
    Shiftout D1PIN, C1PIN, MSBFIRST,[0]
    goto Main
    end

    Is this ok? im getting the programmer ready now and i just wanted to get some input before i actually program it because its my first project.

    Thanks in advance,
    Shahar Zrihen.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The 74HC595 also needs a "Latch" signal. (3 pins, clk, data, latch)

    I think it's called RCLK in the datasheets.
    <br>
    DT

  3. #3
    Join Date
    Jan 2008
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    First of all, Thanks darren for the quick reply.
    so i need to put an extra pin - can i use porta.2?
    and just take it low and high before and after shifting right?
    Thanks again,
    Shahar

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by manjero View Post
    First of all, Thanks darren for the quick reply.
    No problem Shaharn.

    >> so i need to put an extra pin - can i use porta.2?

    Yes!
    But before you can use any of the PORTA pins, including the ones you have already used, you need to turn off the Analog functions.

    CMCON0 = 7
    ANSEL = 0

    >> and just take it low and high before and after shifting right?

    A simple HIGH/LOW toggle of the Latch after shifting will do it. The 595 is a very fast chip.

    But there are more problems too.
    Code:
    Main:
        sleep 1000
        Shiftout D1PIN, C1PIN, MSBFIRST,[0]
        goto Main 
    end
    sleep 1000 will put the PIC in low power mode for somewhere around 1000 seconds. (16 minutes, 40 seconds)

    sleep 60 would be closer to 1-minute, but it'll only be "somewhere around" a minute, since it uses the Watch Dog Timer..

    PAUSE 60000 ; would be a better approximation, without resorting to Timers.<hr>
    >> Shiftout D1PIN, C1PIN, MSBFIRST,[0]
    That's going to shift out 8-bits. So 8 of the LED's will turn off at the same time.

    The way you're doing it, you don't really need the shiftout statement in the Main loop.

    First, set the Data pin to 0 before going into the loop.
    Then after each minute toggle the Clock pin once, to shift in a 0.
    Then toggle the Latch Pin, to move the data to the 595's output's.

    <hr>Also, the first ShiftOut's can be combined...
    Code:
    Shiftout D1PIN, C1PIN, MSBFIRST,[bvar, bvar, bvar, bvar]
    <br>
    DT

  5. #5
    Join Date
    Jan 2008
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Hey DT.
    Thanks again - that was very informative!
    I changed my code to this:

    Include "modedefs.bas" ' Include shift modes

    CMCON0 = 7
    ANSEL = 0
    DPIN var PORTA.0 ' Shift data pin 1
    CPIN var PORTA.1 ' Shift clock pin 1
    LPIN var PORTA.2 ' Latch pin 1


    bvar var BYTE

    bvar = 255
    ' Shift out 8 bits of data onto other pins
    Shiftout DPIN, CPIN, MSBFIRST,[bvar, bvar, bvar, bvar]
    Low DPIN

    Main:
    pause 5980
    High CPIN
    pause 10
    'Shiftout D1PIN, C1PIN, MSBFIRST,[0]
    LOW CPIN
    Pulsout LPIN,10
    goto Main
    end

    Compiles OK so lets hope :-)

  6. #6
    Join Date
    Jan 2008
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Hello manjero, I think that Darrel missed the fact that you're using an 'F84. You can drop the:-

    CMCON0 = 7
    ANSEL = 0

    The 'F84 doesn't have any analogue inputs to turn off or configure as digital IO. They're always digital IO. In fact, I have 16F84(A) selected, the compiler, (v 2.44), doesn't even recognise CMCON0.

    ... Steve (Yep, another one)

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scarroll01 View Post
    In fact, I have 16F84(A) selected, the compiler, (v 2.44), doesn't even recognise CMCON0.
    ... Steve (Yep, another one)
    The upgrade covers that too, only $25.
    Get your now...hurry hurry hurry.

  8. #8


    Did you find this post helpful? Yes | No

    Default

    the 16F684 does

    [/QUOTE]Hello manjero, I think that Darrel missed the fact that you're using an 'F84. You can drop the:-

    CMCON0 = 7
    ANSEL = 0

    The 'F84 doesn't have any analogue inputs to turn off or configure as digital IO. They're always digital IO. In fact, I have 16F84(A) selected, the compiler, (v 2.44), doesn't even recognise CMCON0.
    [/QUOTE]

    I built the circuit using 4 74hc595 cascaded and with a pic16f684 i had laying around with a 4 MHZ xtal.

  9. #9
    Join Date
    Jan 2008
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by bbarney View Post
    the 16F684 does
    Hello manjero, I think that Darrel missed the fact that you're using an 'F84. You can drop the:-

    CMCON0 = 7
    ANSEL = 0

    The 'F84 doesn't have any analogue inputs to turn off or configure as digital IO. They're always digital IO. In fact, I have 16F84(A) selected, the compiler, (v 2.44), doesn't even recognise CMCON0.
    [/QUOTE][/QUOTE]

    Sorry, it's my failing eyesight. I didn't see the "6" and thought it was a PIC16F84.

    ... Steve

  10. #10


    Did you find this post helpful? Yes | No

    Default

    I only seen the 6 cause I know Darrel doesn't miss anything

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by bbarney View Post
    I only seen the 6 cause I know Darrel doesn't miss anything
    Uht-Oh, I'm getting a reputation.


    Quote Originally Posted by manjero View Post
    I changed my code to this: ...
    That's getting closer, but Wait, there's More.

    The Latch Pin should start out LOW.
    Then after the SHIFTOUT, the data gets latched by toggling it High/Low.

    The pause only adds up to about 6000 (6 seconds).
    For 60 Seconds, you need 60,000.

    And the 595 is a really fast chip. pause 10 and Pulsout aren't needed.

    Code:
    bvar = 255
    
    LOW  LPIN       ; Latch Idles LOW
    
    ' Shift out 32 - 1's to 74HC595's
    Shiftout DPIN, CPIN, MSBFIRST,[bvar, bvar, bvar, bvar]
    
    HIGH LPIN       ; Latch data to 595's outputs
    LOW  LPIN
    
    Low DPIN        ; Set Data to 0
                               
    Main:
        pause 60000 ; Wait 1 minute
    
        HIGH CPIN   ; clock in a 0
        LOW  CPIN
    
        HIGH LPIN   ; Latch data to 595's outputs
        LOW  LPIN
    GOTO Main
    hth,
    DT

Similar Threads

  1. newbie with serial com question...
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th December 2006, 05:34
  2. Newbie Question - Info Please
    By ehoskins in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 2nd October 2006, 14:50
  3. Greetings from Newbie and a question
    By ChrisHelvey in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 24th July 2006, 15:52
  4. Newbie question
    By senojlr in forum General
    Replies: 7
    Last Post: - 11th April 2006, 21:23
  5. Replies: 4
    Last Post: - 8th September 2005, 15:42

Members who have read this thread : 1

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