Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

74HC595 Shift

Status
Not open for further replies.

AtomSoft

Well-Known Member
Hey guys i know im a pain heh but i wrote this code and want some info... should i latch every byte or every 2 bytes? I have 2 daisy chained 74hc595's and want to get this right.

Code:
void shiftIt(REGT Data){
unsigned char REGCount = 2;
unsigned char reg;
unsigned char value;
unsigned char x;

	Delay100TCYx(60);	//15 magic #
	LATCH = 0;	   
	for (reg=0; reg<REGCount; reg++){
	    value = (char)(Data >>(8*reg));
		for (x=0; x<8; x++){
			CLK = 0;
	      	//if(value&0x01)
			if(value&0x80)
				SDO = 1;
			else
				SDO = 0;

	       	CLK = 1;
			//value >>= 1;
			value <<= 1;
		}
	}
	LATCH = 1;
}
 
Heh thanks... Its nothing big... Just got a project to do for a family member (POPS).
He owns a Flower shop and want me to make a HUGE 4'(FOUR FEET) long LED Matrix heh i know
huge right heh. At least its only 1 line heh...

I will surely use a 8x8 Matrix but for testing i want to use these 5x7 Matrixs i have here and
so far no good. I had something working slighlty but my code was off i guess. I might remove the
smooth scrolling and just move letter by letter heh... this will save me a headache i guess...

But i want to make sure i was using the 74HC595 correctly to begin with
 
Hi Jason,

At first glance, the code posted looks like it should work; well, it should shift out two bytes MSB first anyway. So what's the actual problem with the display? Are you scanning the matrix as well?

I thought it a bit odd that you used "value = (char)(Data >>(8*reg));" though. As you expand the number of shift registers, you'll have to shift more bytes than you can fit in the largest data type - I would've thought passing a char array in would the more obvious choice.
 
Last edited:
Forgot to say REGT is a 24Bit number. heh.... so its capable of 3 bytes which is 3 595's. That part seems to work ok.. I might make it 1 byte but not sure yet. I forgot i have proteus and will simulate it with normal LEDs to see rows...
 
This seems to show ok so far:
Code:
void shiftIt(REGT Data){
unsigned char reg;
unsigned char value;

	Delay10KTCYx(100);	//15 magic #
	value = 1;
	for (reg=0; reg<10; reg++){
		CLK = 0;
		Delay100TCYx(10);
		CLK = 1;
		value = 0;		
	}
	LATCH = 0;
}

This was a test... so now ima have it with input
 
Last edited:
Working well with:
Code:
void shiftIt(REGT Data){
unsigned char reg;

	LATCH = 0;
	for (reg=0; reg<16; reg++){
		CLK = 0;
		
		if(Data&0x8000)
			SDO = 1;
		else
			SDO = 0;

		Delay10TCYx(1);
		CLK = 1;

		Data <<= 1;
	}
	LATCH = 1;
	Delay10TCYx(1);
	LATCH = 0;

}
 
heh yeah the latch types are great for things like LCDs and such. Where output is more important.

Once i get started with AVR.. i plan on getting a 24bit Bus wide LCD (color 3.5in) which uses 24bits just for color info. I plan to use these to load the color data and regular I/O to control other lines
 
A few reasons are... Price/Speed

ATTINY48-AU Atmel Microcontrollers (MCU)

usually 1 MIP per MHZ so its a 1:1 ratio and most instructions are single cycle so its worth it... and under $2 ? wow then if you shell out for a $4-$8 chip you get way more...

ATXMEGA16A4-AU Atmel Microcontrollers (MCU)

$5 you cant go wrong

Its way easier to use in C than a PIC. Where you have to always alter a linker file to make space. Which sux ... i dont understand why they did it that way at all. It just seems like the most logical choice for me to make...
 
castcading 595's

When I worked on a project using 595 shifts it was easy enough to cascade em but coding was a trip. when I sent something to the first 595 it ran ok but when I sent a second line for the next colum and shifted the 595's what was in the first 595 went to the second an then down the line, never did get right so I switched to 4017's instead. Much easier t o code for. I use Pic's in asm.
gogo
 
Last edited:
yeah that seems to be my issue with 595s they dont want to work the way i think they should heh... if i shift out 3 bytes it should get the 3 bytes 1 for each... but no it has a mind of its own...
 
The problem with shift is that they shift data to the next register. what I tried was shifting data to the first one then loaded no data the second time and the third, when I shifted it 3 times the data traveled across the three 595's. I played with that for awhile then I wrote a tabe like this
shift_Table
b'00000001'
b'00000000'
b'00000000'
b'00000010'
b'00000000'
b'00000000'
b'00000100'
b'00000000'
b'00000000'
and so on the table got kind of long so I opted to try and write some kind of loop instead finally I just switch to 4017's, much easier all you have to do is cascade them with a and Gate and clock em. A basic Idea of this is at



if you follow his site he has some pretty neat stuff ther little dated but still good even has a 7x15 scrolling message sign that can be programed too.
gogo
 
Last edited:
Jason,
Maybe if you think on several cascaded 595's a one longer shift register rather then several smaller ones?

Cascaded 595's are not difficult to use. All 595's must share the same clock and latch lines. Serial data output of each stage to the serial data input of the next. Shift in as many bits as you need and then latch them to the output.

Latching the data to the outputs does not change the contents of the shift register. You could latch after every shift, after the last shift the outputs would be the same as if you only did the final latch.

Make sure you are shifting out what you want in the expected order.

3v0
 
Last edited:
i know that. Remember my old code from here it would take a 24 bit number like 0000-0000-0000-0000-0000-0001 and shift it out to the 3 registers then i shift that number like << 1

0000-0000-0000-0000-0000-0010 will be the next shifted number.... but it didnt work right for some reason.
 
castcading 595's

Well at the time I was trying to create a raster scroll with th 595's scrolling one bit of data down a column of leds and it was not working out I think the table was about as close as I came.
I put the project down at the time because it was straight out deterring me fro my hobby. The whole set up was on a bread board with wires hanging all over the place and hafe the time I didn't understand what was going wrong, you know, was it my code was it a wire or on board capacitance who knew, so I decided to put it away for awhile but I still have plans to get back into it. I have a bunch of 8x8 led arrays I plan on making a PCB for as soon as I can figure out KiCad. Yep my hobby is a on going lesson.
I'll keep you posted.
gogo

ps I have a small scrolling message sign working with 4017's on a bread board, (7 x 24 ) I think that is what keeps me interested.
 
NOTE: Got it working perfect using :

Code:
				for (y = 0; y < 8; y++) {
					LEDPort = 0;
					LATCH=0;
					LEDPort = message[num][y];
					shiftOut((1<<y),MSB);
					LATCH=1;
					Delay10TCYx(22);
				}
 
Status
Not open for further replies.

Latest threads

Back
Top