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.

[51] 74HC595 with 16 leds issues

Status
Not open for further replies.

sp2012

Junior Member level 3
Junior Member level 3
Joined
Mar 20, 2012
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Banglore
Activity points
1,512
Hi to all,

I am using 8051 and two 74HC595 shift register to control 16 leds.

In my schematics:

1st HC595 QA to QH connected to 8 leds
and
2nd HC595 QA to QH connected to next 8 leds.

1st HC595 Clock and 2st HC595 Clock pin connect to P1.2
1st HC595 latch and 2st HC595 latch pin connect to P1.3
1st HC595 serial data input connected to P1.4

and 1st HC595 QH'(9th pin) connected to 2nd HC595 serial data(14th pin)

and gnd(8 and 13th pin),vcc(16 and 10th pin) both HC595 given.

Thats all in schematics.

and my code are:

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
void delay(int a)
{
   int i;
   for(i=0;i<a;i++);   //null statement
}
 
void HC595_DISPLAY(unsigned char dat)
{
    HC_LATCH = 0;
    HC_CLK=0;
    for(cnt=0;cnt<8;cnt++)
    {
        HC_DATA     =       dat & 0x01;
        HC_CLK      =       1;
        delay(2);
        HC_CLK      =       0;
        delay(2);
        dat = dat >> 1;
    }
    HC_LATCH = 1;
}
int main()
{
    while(1)
    {
        HC595_DISPLAY(0xf0);
    }
}



Here in my led output
1st HC595 4leds on
and
2nd HC595 4leds on.

I need to toggle one by one leds.
Can anybody guide me how to do this please?

Regards
surya
 
Last edited by a moderator:

The following example might do what you want. It should turn on 1 LED at a time in sequence.

Code:
#include <mcs51/at89c51ed2.h>

#define HC_LATCH P1_3
#define HC_CLK P1_2
#define HC_DATA P1_4

int cnt;

void delay(int a)
{
  int i;
  for(i = 0; i < a; i++); //null statement
}


void HC595_DISPLAY(unsigned char dat)
{
  HC_LATCH = 0;
  HC_CLK = 0;
 
  for(cnt = 0; cnt < 16; cnt++)  
     {
     HC_DATA = (dat & 0x01);    
    
     HC_CLK = 1;
     delay(2);
     HC_CLK = 0;
    
     delay(2);
         
     HC_LATCH = 1; 
     delay(2);
     HC_LATCH = 0;
     
     delay(0x600);  // delay long enough to see LEDS
       
     dat = dat >> 1;
     } 
}


int main()
{
  while(1)
    { 
    HC595_DISPLAY(0x0001);
    }
}
 

do it in a following way :


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
void delay(int a)
{
   int i;
   for(i=0;i<a;i++);   //null statement
}
 
void HC595_DISPLAY(unsigned char dat)
{
    HC_LATCH = 0;
    HC_CLK=0;
    for(cnt=0;cnt<8;cnt++)
    {
        HC_DATA     =       dat & 0x01;
        HC_CLK      =       1;
        delay(2);
        HC_CLK      =       0;
        delay(2);
        dat = dat >> 1;
    }
    HC_LATCH = 1;
}
int main()
{
    while(1)
    {
        HC595_DISPLAY(0x00);
        HC595_DISPLAY(0x01);
        delay (2000);
        HC595_DISPLAY(0x00);
        HC595_DISPLAY(0x00);
    }
}

 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top