Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Questions bout shiftregisters (74HC575, 74HC597)

Status
Not open for further replies.
Re: Questions About some shiftregisters

The 5595 serial output circuit is O.K., except for the 1 µF capacitor at /SS. I guess, the author wanted to place it at VCC.
 
Re: Questions About some shiftregisters

what' wrong with my steps? I can't get it work... ;(


PHP:
void init_output()
{
	TRISDbits.TRISD3 = 0;
	TRISDbits.TRISD4 = 0;
	TRISDbits.TRISD2 = 0;
	TRISCbits.TRISC5 = 0;

	SPI_OE = 0; //output enable
	SPI_OutClr = 1; //MR
	SPI_OutLatch = 1; //ST_CP
	
	
	
}

void output_data(unsigned int data)
{
	char i;
	SPI_OutLatch = 0;
	for(i = 7 ; i >= 0 ; i--)
    {
		if(((data >> i) & 0X01) == 0) 	SPI_SO =   0; //DS
        else 							SPI_SO =   1;
		clock();

    }
	SPI_OutLatch = 1;
}

void clock()
{
	SPI_Clk = 0;
	delayus(1);
	SPI_Clk = 1;

}
 

Re: Questions About some shiftregisters

You're using different pin names in every post, how should we know, what the code is actually doing.

You should post a complete test code, including all signal definitions, initializations and main().
 
Re: Questions About some shiftregisters

Hi FVM,

This is the code.
the previous code was for another shift register


PHP:
#include<htc.h>

#define SPI_Clk PORTCbits.RC3 //sh_cp
#define SPI_SO PORTCbits.RC5 //DS
#define SPI_OutLatch PORTDbits.RD2 //st_cp
#define SPI_OutClr PORTDbits.RD4 //MR
#define SPI_OE PORTDbits.RD3 //OE

void init_ports();
void send_data(unsigned int data);
void main()
{
	init_ports();
	while(1)
	{
		send_data(0x77);
	}

}


void init_ports()
{
	/* make outputs */
	TRISCbits.TRISC3 = 0;
	TRISCbits.TRISC5 = 0;
	TRISDbits.TRISD2 = 0;
	TRISDbits.TRISD4 = 0;
	TRISDbits.TRISD3 = 0;

	SPI_OE = 0;
	SPI_OutClr = 1;
	SPI_OutLatch = 1;
	
	

}

void send_data(unsigned int data)
{
	char i;

	for(i = 7 ; i >= 0 ; i--)
    {
		if(((data >> i) & 0X01) == 0) 	
		SPI_SO =   0;
        else 							
		SPI_SO =   1;

		

    }
	SPI_Clk = 0;
	SPI_Clk = 1;
	
       SPI_OutLatch = 0; //latch to parallel output pins

}
 

Re: Questions About some shiftregisters

You didn't mention the chip you are trying to use, is this for 74HC595?
 

Re: Questions About some shiftregisters

operation of 74HC595

Set MR=1
Set OE=0
Set STCP=0
Set SHCP=0

Give to DS the value of D7
toggle SHCP (to 1 and back to 0)
Give to DS the value of D6
toggle SHCP (to 1 and back to 0)
....
Give to DS the value of D0
toggle SHCP (to 1 and back to 0)
toggle STCP (to 1 and back to 0) to see the data in the output

SHCP shifts the data without changing the output state, when you are done shifting you toggle STCP to output the result

Alex
 
Last edited:
Re: Questions About some shiftregisters

nothing happens..

should I give a delay between toogle?

PHP:
#define SPI_Clk PORTCbits.RC3 //sh_cp
#define SPI_SO PORTCbits.RC5 //DS
#define SPI_OutLatch PORTDbits.RD2 //st_cp
#define SPI_OutClr PORTDbits.RD4 //MR
#define SPI_OE PORTDbits.RD3 //OE

void clock_data();
void init_ports();
void send_data(unsigned int data);
void latch_output();

void main()
{
	init_ports();
	while(1)
	{
		send_data(0x77);
	}

}


void init_ports()
{
	/* make outputs */
	TRISCbits.TRISC3 = 0;
	TRISCbits.TRISC5 = 0;
	TRISDbits.TRISD2 = 0;
	TRISDbits.TRISD4 = 0;
	TRISDbits.TRISD3 = 0;

	SPI_OutClr = 1;
	SPI_OE = 0;
	SPI_OutLatch = 0;
	SPI_Clk = 0;
	
	
	
	
	

}

void send_data(unsigned int data)
{
	char i;

	
	for(i = 7 ; i >= 0 ; i--)
    {
		if(((data >> i) & 0X01) == 0) 	
		SPI_SO = 0;
		else
		SPI_SO = 1;

		clock_data();

    }
	latch_output();

}


void clock_data()
{
	SPI_Clk = 1;
    SPI_Clk = 0;
}


void latch_output()
{
	SPI_OutLatch = 1;
	SPI_OutLatch = 0;

}


---------- Post added at 15:43 ---------- Previous post was at 15:37 ----------

I added 1ms delay.. still not working.
the datasheet says the toogle should be from 0 to 1.. I already tried still not working..
 

Re: Questions About some shiftregisters

I don't see a problem in your code so try the delays

also

Code C - [expand]
1
2
3
4
if(((data >> i) & 0X01) == 0)     
        SPI_SO = 0;
        else
        SPI_SO = 1;



has the same result as

Code C - [expand]
1
SPI_SO= ((data >> i) & 1);



---------- Post added at 16:45 ---------- Previous post was at 16:44 ----------

are you trying in proteus, because the 74HC595 works fine there if you use logicstate to give the inputs
 

Re: Questions About some shiftregisters

I added 1ms delay.. still not working.
the datasheet says the toogle should be from 0 to 1.. I already tried still not working..


yes Im trying with proteus..

what do you mean by logicstate to give the inputs?
 

Re: Questions About some shiftregisters

in the debugging tool category (in the components screen) there are two components named LOGICSTATE that has a latched action and LOGICTOGGLE that has a momentary action

use the circuit below with LOGICSTATE
Snap1.gif

toggle the SHCP three times (while DS=1) and then toggle the STCP and you will see the result
 
Re: Questions About some shiftregisters

in the debugging tool category (in the components screen) there are two components named LOGICSTATE that has a latched action and LOGICTOGGLE that has a momentary action

use the circuit below with LOGICSTATE
View attachment 60823

toggle the SHCP three times (while DS=1) and then toggle the STCP and you will see the result


wow!!! I've got an idea how to debug... yes it's working..
I have a feeling that there is no laching happened in my code..although the code is correct but there something wrong. hehe
 

Re: Questions About some shiftregisters

use the digital analysis graph to see the output states that the pic sends (place a probe in each input pin and add it to the graph)

Also make sure that the pic outputs work as I/O , I think some pins have as default some other function but since I haven't used pic I can't help on that
 
Re: Questions About some shiftregisters

in the debugging tool category (in the components screen) there are two components named LOGICSTATE that has a latched action and LOGICTOGGLE that has a momentary action

use the circuit below with LOGICSTATE
View attachment 60823

toggle the SHCP three times (while DS=1) and then toggle the STCP and you will see the result


wow!!! I've got an idea how to debug... yes it's working..
I have a feeling that there is no laching happened in my code..although the code is correct but there something wrong. hehe


I see now the culprit.. the latch pin is not latching..
the latchpin si working with blinkin LED program but I dont know what happen.. I wil try again..

---------- Post added at 16:29 ---------- Previous post was at 16:12 ----------

this is the problem why not latching.. I dont know why it si happening.. it's not exiting in the for loop



PHP:
void send_data(unsigned int data)
{
	char i;

	
	for(i = 7 ; i >= 0 ; i--)
        {
		clock_data();
		if(((data >> i) & 1) == 0) 	
		SPI_SO = 0;
		else
		SPI_SO = 1;
		
	}
        latch_output();
	//blinking led program

}

in the code above the led is not blinking meaning it is not exiting in the loop


bu if I will place in inside the loop the led is blinking and also if I put the latch inside loop it will latch... why is that so?
 

Re: Questions About some shiftregisters

i is a char, it can take values from 0 to 255 and you are using i >= 0 (7,6,5,4,3,2,1,0,255,254...), i is always >=0
 
Re: Questions About some shiftregisters

i-- is the action it should go below zero not increment.... Im confuse now about loops :)
 

Re: Questions About some shiftregisters

i is a char 0x00 to 0xff this is the equivalent of 0 to 255, when it has the value of 0 and you subtract 1 it goes to 255 (0b11111111)
 
Re: Questions About some shiftregisters

I dont understand :)

my foor loop starts from 7 so the initial value of for loop is 7 not zero.

for(i=7; i>=0; i--)

---------- Post added at 16:43 ---------- Previous post was at 16:39 ----------

look at this.. hehe I added like this to latch ad exit in foor loop

now it is working by manually exiting the loop.. hehe

I will try another kind of loop but Im very puzzled why it's not exiting


PHP:
	for(i=7; i>=0; i--)
    {
		
		if(((data >> i) & 1) == 0) 	
		SPI_SO = 0;
		else
		SPI_SO = 1;

		clock_data();
		if(i<1)
		break;
		
	}
	latch_output();
 

Re: Questions About some shiftregisters

yes it is 7 then 6 then 5 then 4 then 3 then 2 then 1 the 0
but the condition i>=0 is still true (i greater or equal to 0) so it continues 255 (i greater or equal to 0) then 254 then 253....
you have to use i>0
 
Re: Questions About some shiftregisters

hehe sorry I was wrong.. now it's working


I change something like this


PHP:
	for(i=0; i<8; i++)
    {
		
		if(((data << i) & 0x80) == 0) 	
		SPI_SO = 0;
		else
		SPI_SO = 1;

		clock_data();
		
	}
	latch_output();


thanks so much alexan_e . I learned now about for loop :) :roll::roll::roll::roll::roll::roll:


I spent more than 8 hours for a faulty for loop of mine... huhhuhuhu
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top