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] 89s52 interfacing with 74HC595 shift register program

Status
Not open for further replies.

thannara123

Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,580
Helped
122
Reputation
244
Reaction score
114
Trophy points
1,353
Location
India
Activity points
10,377
Hello experts ,
I am interfacing 89s52 with 74HC595 shift register .
please help me what is the error the following code written Keil

#include <REGX51.H>
#include<delay.h.>
unsigned char gk,gireesh = 0x18;
unsigned int i;


void main()
{
P0 = 0x00;
P2 = 0x00;
P1 =0x00;
while(1)
{


P1_3 =0; // ST_Cp
delay(10);
P1_3 =1; // ST_cp




for (gk = 0x80; gk; gk>>=1)
{

P1_0 = 1; // SH_CP
delay(10);
P1_0 = 0; // Sh_CP


if (gireesh&gk)
{
P1_2 = 1; // Data
}
else
{
P1_2 = 0; // Data
} }
}

for(i=0; i<9; i++)
{
P2 = (1<<i); // data for scaing


delay(100);



} }



​
 
I would suggest you try to drive some simple leds using the 74595 and if that works correctly then try to use multiplexing in a led display.

Check this article **broken link removed**
scroll down about half way to Using the 74HC595 – Control 16 LEDs

This may also help https://www.edaboard.com/threads/222857/#post949459

Alex
 
Did you try with the shift register and 8 leds to check that you can send the data correctly?
If that step doesn't work it is pointless to try more complicated code.

Alex
 

no sir now i am trying to for that thanks
 

please see the program ,


#include <REGX51.H>

#include<delay.h>

void sendserial(unsigned char);

unsigned char a[] = { 0x70, 0x88, 0x80, 0x70, 0x08, 0x88, 0x70 };

unsigned int i, j, l, k, temp;
unsigned int k = 8;
void main()
{
P0 = 0x00;
P3 = 0x00;
while (1) {


for (i = 0; i < 8; i++) {
temp = ~a[i];

sendserial(temp);

for (l = 0; l < 10; l++) {
P2 = (1 << i);
}

P3_1 = 1;
// ST_CP
P3_1 = 0;
}
void sendserial(unsigned char gireesh) {
unsigned char gk;
for (gk = 0x80; gk; gk >>= 1) {
P3_0 = 1; // SH_CP
P3_0 = 0;

if (gireesh & gk) {
P3_2 = 1; // Data
delay(1);
} else {
P3_2 = 0; // Data
delay(1);
}

}

}





my problem how can i shift or move the character ?
i given toggle signal to ST_CP but nothing happend
please help me thanks
 
Last edited:

I don't see you following this

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


start by changing your function to

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void sendserial(unsigned char gireesh) {
    unsigned char gk;
    for (gk = 0x80; gk; gk >>= 1) {
 
        if (gireesh & gk) {
            P3_2 = 1; // Data
            delay(1);
        } else {
            P3_2 = 0; // Data
            delay(1);
        }
 
        P3_0 = 1; // SH_CP
        P3_0 = 0;
    }
}


and why is your function inside the main?

Alex
 
Set MR=1 given vcc directly to the 74HCT595 pin 10
Set OE=0 given ground directly to 74HCT595 PIn 13
Set STCP=0 is it means initilisation ?
Set SHCP=0 '' ''



Sir the Fuction is written outside the main function is it ?

i gived all data as you said
 

Your posted code was


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
void sendserial(unsigned char);
 
unsigned char a[] = { 0x70, 0x88, 0x80, 0x70, 0x08, 0x88, 0x70 };
 
unsigned int i, j, l, k, temp;
unsigned int k = 8;
void main()
{
    P0 = 0x00;
    P3 = 0x00;
    while (1) {
 
 
        for (i = 0; i < 8; i++) {
            temp = ~a[i];
 
            sendserial(temp);
 
            for (l = 0; l < 10; l++) {
                P2 = (1 << i);
            }
 
           P3_1 = 1;
// ST_CP
            P3_1 = 0;
        }
        void sendserial(unsigned char gireesh) {
            unsigned char gk;
            for (gk = 0x80; gk; gk >>= 1) {
                P3_0 = 1; // SH_CP
                P3_0 = 0;
 
                if (gireesh & gk) {
                    P3_2 = 1; // Data
                    delay(1);
                } else {
                    P3_2 = 0; // Data
                    delay(1);
                }
 
            }
 
        }



there are some brackets missing at the end but I don't see the main ending before the sendserial starts so I suppose that you are missing brackets in the middle too.

What I have commented in my previous post was that you were using

toggle SHCP (to 1 and back to 0)
Give to DS the value of Dx

instead of
Give to DS the value of Dx
toggle SHCP (to 1 and back to 0)


Set STCP=0 is it means initilisation ?
Set SHCP=0 '' ''

yes these are the initialization values
 
Give to DS the value of Dx
Dx means ?
the data comes to out put and i can see the output character but there was no shifting.
 

Dx is D7, D6, D5, D4....D0 as shown in post #6

Alex
 

I don't see the relevance of the picture, I have just commented that you had the wrong order in data and clock in your code

Alex
 

Sir i re edited my program as your lecture but nothing to more happen
#include <REGX51.H>
#include<delay.h>
void sendserial(unsigned char);
unsigned char a[]={ 0x70, 0x88, 0x80, 0x70, 0x08, 0x88, 0x70 };
unsigned int i ,j,l,k,temp;
unsigned int k =8;
void main()
{
P0 = 0x00;
P3 = 0x00;
while(1)
{
P3_0 = 0; // SH_CP intilization
P3_1 = 0; // ST_CP Intilization
for(i=0; i<8; i++)
{
temp = ~a[i];
sendserial(temp);
P3_1 = 1; // ST_CP
P3_1 = 0;
for(l=0; l<10; l++)
{
P2 =(1<<i);
}
}
void sendserial(unsigned char gireesh)
{
unsigned char gk;
for (gk = 0x80; gk; gk>>=1)
{
if (gireesh&gk)
{
P3_2 = 1; // Data
delay(1);
}
else
{
P3_2 = 0; // Data
delay(1);
}
P3_0 = 1; // SH_CP
P3_0 =0;
}
}
 

Your code is still missing some brackets, as it is it will not even compile.

I have added the two brackets and removed some loops so we can see if the 74HC595 works

Code:
void sendserial(unsigned char);
unsigned char a[]= { 0x70, 0x88, 0x80, 0x70, 0x08, 0x88, 0x70 };
unsigned int i ,j,l,k,temp;
unsigned int k =8;
void main()
{
    P0 = 0x00;
    P3 = 0x00;
    while(1)
    {
        P3_0 = 0; // SH_CP intilization
        P3_1 = 0; // ST_CP Intilization
        // for(i=0; i<8; i++)
        {
           [B][COLOR="#FF0000"] //temp = ~a[i];[/COLOR][/B]
		[B][COLOR="#0000FF"]temp=0x0f;[/COLOR][/B]
            sendserial(temp);
            P3_1 = 1; // ST_CP
            P3_1 = 0;
            [B][COLOR="#0000FF"]P2=0xff;[/COLOR][/B]
			
		[B][COLOR="#FF0000"]	/* for(l=0; l<10; l++)
            {
                P2 =(1<<i);
            } */[/COLOR][/B]
        }
    }
}

void sendserial(unsigned char gireesh)
{
    unsigned char gk;
    for (gk = 0x80; gk; gk>>=1)
    {
        if (gireesh&gk)
        {
            P3_2 = 1; // Data
            delay(1);
        }
        else
        {
            P3_2 = 0; // Data
            delay(1);
        }
        P3_0 = 1; // SH_CP
        P3_0 =0;
    }
}

I have commented the red parts and added the blue parts, this should send the value 0b00001111, you should see half of the leds on and half of them off
Does this work?

Alex
 
yes output got
but is here the data shift ?
(scrolling effect ? )
sir now confusing totally what will the above program output i got LSB blinks
 
Last edited:

OK, so the 74HC595 works correctly now?
Have you tried to show one character to see if it is shown correctly?

Alex
 
Yes i can see some character is the above program .
now also i changes the program
the program also shows some character
how can i shift the data to the next position for the moving
#include <REGX51.H>
#include<delay.h>
void sendserial(unsigned char);
unsigned char temp;
unsigned char a[] = { 0x70, 0x88, 0x80, 0x70, 0x08, 0x88, 0x70 };

unsigned int i;

void main()
{
P2 = 0x00;
P3 = 0x00;

while (1) {
delay(10);
for (i = 0; i < 8; i++) {
P2 = (1 << i);
sendserial(~a);
delay(1);
}
}
}









void sendserial(unsigned char gireesh)
{
unsigned char gk;
P3_0 = 0;
P3_1 = 0;

for (gk = 0x80; gk; gk >>= 1) {
if (gireesh & gk) {
P3_2 = 1; // Data 1
} else {
P3_2 = 0; // Data 0
}
P3_0 = 0; //shcp
P3_0 = 1;// shcp
}
P3_1 = 1; //stcp


}
 
how can i shift the data through the next bit address ?
i am only able to see the serial data to parallel data
please help me .
 

I don't understand
how can i shift the data to the next position
shift the data through the next bit address

What are you trying to do?
Do you want to move the character out of the screen?

You can try to shift the data, after showing 0x70, 0x88, 0x80, 0x70, 0x08, 0x88, 0x70 start shifting the data so that they move one position at a time

so do additional loops after the original one using
sendserial(~(a<<1));
sendserial(~(a<<2));
sendserial(~(a<<3));
etc

Alex
 
after outputting (Q0 to Q) , can i shift the data as follows
Q0 data need to be available at Q1,Q1 data available at Q2 etc ?
can i do so as ?
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top