1. tommer5k

    Thread Starter New Member

    Jan 10, 2013
    7
    0
    Hi,

    I'm trying to program a string of leds to blink with a sn74hc595n.

    I have 8 leds in total with the 74hc959 sinking each led, 220 resistor to each. OE is pulled to ground via resistor and srclk is to 5v. The breadboard is being sourced by a pickit2 at 5v. I'm using only the 1 shift register.

    The problem is that all of the leds are on all the time. It doesn't seem to matter what i do to the code.

    Also, i can't figure out why, except possibly that it's detecting a pulse(?) but when i jiggle the breadboard, or insert and remove power to the bb, some leds will turn off or all or none etc. I'm using an 18f2220. I have not tried the spi module or mikroc library as i wanted to get bit bang down first. a good portion of this code is not mine either, pieces were borrowed form several places. any advice/help would be appreciated

    Code ( (Unknown Language)):
    1. #define clock PORTB.F2
    2. #define latch PORTB.F1
    3. #define data PORTB.F0
    4.  
    5. void portOut (unsigned char buff)
    6. {
    7.      unsigned int i;
    8.      unsigned char temp;
    9.      temp = buff;
    10.      i=8;
    11.      while (i>0)
    12.      {
    13.         if (temp==0) data = 0;
    14.         else         data = 1;
    15.         temp = temp << 1;
    16.         clock = 1;
    17.         delay_us(1);
    18.         clock = 0;
    19.         i--;
    20.         }
    21.    latch = 1;
    22.    delay_us(1);                                  // Latch the data
    23.    latch = 0;
    24. }
    25.  
    26.  
    27. void main()
    28. {
    29. TRISB = 0;
    30. LATC=0;
    31. delay_ms(85);
    32. while(1)
    33. {
    34. portOut(170);
    35. delay_ms(250);
    36. portOut(0b11001100);
    37. delay_ms(85);
    38. }
    39. }
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    SRCLK at +5V sounds like a really bad thing to do. How did you come up with this arrangement? As always in these cases, why do you imagine that a textual description is an adequate substitute for a schematic diagram? It like describing your baby in words and asking us if we think it is beautiful. It is really hard to tell, but maybe a picture would help. On the other hand maybe your baby is just plain ugly.
     
    absf and tshuck like this.
  3. tommer5k

    Thread Starter New Member

    Jan 10, 2013
    7
    0
    I can't tell if those are actual requests for more information or just a string of rhetorical questions sarcasm.

    I'll see if I can put something together when I get home
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Well tommer, here's a hint: just how many people have responded to your query?

    Could it be no one has any idea, but there you sit and question the one person to actually give you a reasonable (and to be honest, painfully obvious) suggestion?
     
  5. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    It is not so hard to get these shifters working, but can be confusing if you are not used to it.


    You can try for instance:

    Code ( (Unknown Language)):
    1.  
    2. sh=0xff;
    3.  
    4. while(sh)
    5. {
    6.  data=0;
    7.  if(sh&data_byte)data=1;
    8.  clk=1;clk=0;
    9.  sh>>=1;
    10. }
    11.  
    12. latch=1;latch=0;
    13.  
    I have not tested but it should be possible to make it working.

    Only experience will tell you how to spell C code in more compact ways.

    I have grown up with BASIC and remember well issues with 0 or 1 index, and the dynamic effects of arithmetics.

    It is sometimes not fully clear and then you write more lines than neccessary.

    I hope my C code isn't totally off somehow but even that can happen just writing it on a forum.

    Use the MPLAB SIM for single stepping.
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    The suggestion to post a schematic diagram is almost universally the first suggestion when anybody asks a circuit question. Trying to imagine what is going on from a textual description is nearly impossible. The baby analogy is just another way of saying in blunt terms that a picture is worth thousands of words. You may have grown up in a feel good environment where everybody was concerned with your tender feelings. I thought that I made two definitive suggestions and asked a single question about how you came up with your circuit. If you had said "I copied it from a magazine" that would have been helpful. If on the other hand you said, "Well, I just threw some components on a board and wired 'em up as best I could imagine", then that would be a whole different matter. In that case we'd have to go back to basics to explain what the problem was.
     
  7. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    You should have tested it. ;)

    It will work ok, apart from the first line;
    sh=0xff;
    which should be
    sh=0x80;

    as your mask sh requires only ONE bit to be set. :)
     
  8. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,644
    759
    Fathers tend to take lot of time to accept that...! :D :D
     
  9. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    Regardless you just put your arms around them and love them no matter what!!