sn74hc595n

Thread Starter

tommer5k

Joined Jan 10, 2013
7
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

Rich (BB code):
#define clock PORTB.F2
#define latch PORTB.F1
#define data PORTB.F0

void portOut (unsigned char buff)
{
     unsigned int i;
     unsigned char temp;
     temp = buff;
     i=8;
     while (i>0)
     {
        if (temp==0) data = 0;
        else         data = 1;
        temp = temp << 1;
        clock = 1;
        delay_us(1);
        clock = 0;
        i--;
        }
   latch = 1;
   delay_us(1);                                  // Latch the data
   latch = 0;
}


void main()
{
TRISB = 0;
LATC=0;
delay_ms(85);
while(1)
{
portOut(170);
delay_ms(250);
portOut(0b11001100);
delay_ms(85);
}
}
 

Papabravo

Joined Feb 24, 2006
21,228
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.
 

Thread Starter

tommer5k

Joined Jan 10, 2013
7
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
 

ErnieM

Joined Apr 24, 2011
8,377
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?
 

takao21203

Joined Apr 28, 2012
3,702
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:

Rich (BB code):
sh=0xff;
 
while(sh)
{
 data=0;
 if(sh&data_byte)data=1;
 clk=1;clk=0;
 sh>>=1;
}

latch=1;latch=0;
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.
 

Papabravo

Joined Feb 24, 2006
21,228
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
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.
 

THE_RB

Joined Feb 11, 2008
5,438
You can try for instance:

Rich (BB code):
sh=0xff;

while(sh)
{
 data=0;
 if(sh&data_byte)data=1;
 clk=1;clk=0;
 sh>>=1;
}

latch=1;latch=0;
I have not tested but it should be possible to make it working.
...
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. :)
 
Top