problem in interfacing HCS12 with 74HC595 shift register

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

problem in interfacing HCS12 with 74HC595 shift register

1,848 Views
SARY
Contributor III

hi everyone

   I have interfaced MC9S12XHZ512 controller with three 74hc595 IC(shift register) to glow multiple LED from Single data input

The code for driving the led is somewhat like

 

 CPU_LED_LATCH =0;
  CPU_LED_ENABLE = 0;
ulVal is the input to drive any LED.
    ucShiftValue = (ulVal >> 16) & 0xff;
    uci=8;
    while (uci > 0)
    {
        
            CPU_LED_SRCLK=0;
      if((ucShiftValue & 0x80)==0x80)
         CPU_LED_DATA=1;
    else
         CPU_LED_DATA=0;
           CPU_LED_SRCLK = 1;
      
        ucShiftValue = ucShiftValue << 1;    // Shift left or one bit
            uci--;
    }
    ucShiftValue = (ulVal >> 8) & 0xff;
    uci=8;
    while (uci > 0)
    {

        CPU_LED_SRCLK=0;
      if((ucShiftValue & 0x80)==0x80)
          CPU_LED_DATA=1;
      else   
         CPU_LED_DATA=0;
    
      CPU_LED_SRCLK = 1;
    ucShiftValue = ucShiftValue << 1;    // Shift left or one bit
        uci--;
   
    }

    ucShiftValue = ulVal & 0xff;
    uci=8;
    while (uci > 0)
    {
      
        CPU_LED_SRCLK=0;      
       if((ucShiftValue & 0x80)==0x80)
        CPU_LED_DATA=1;    
      else    
         CPU_LED_DATA=0;
       CPU_LED_SRCLK = 1;
    
        ucShiftValue = ucShiftValue << 1;    // Shift left or one bit
          uci--; 
        
    }
       CPU_LED_LATCH=1;

The problem is the that when I am setting single LED on. I am getting fluctuating output on other LEDs also.say if in above code ulVal=1;

   I will get constant o/p on first LED and it is correct.But I am getting fluctuations on other LEDs as well.

DOes anyone know what is the problem ?n how can I get single LED on at at ime with no fluctions on other LEDs.

 

Regards

SARY

Labels (1)
0 Kudos
4 Replies

980 Views
bigmac
Specialist III

Hello Sary,

 

I assume that you have a "daisy chain" connection for the three shift registers.  However, I cannot see a reason for your code being problematic, but I can see where a significant simplification can be made to the code.

 

Since you are "bit banging" the serial interface, there is no reason why all 24 bits cannot be sequentially shifted within a single loop, rather than handling as three separate bytes.

 

void LED_update( unsigned long ulval)(   unsigned char uci;      CPU_LED_ENABLE = 0;  // Enable output to LEDs   CPU_LED_LATCH = 0;      for (uci = 0; uci < 24; uci++) {      CPU_LED_SRCLK = 0;      if (ulval & 0x800000)         CPU_LED_DATA = 1;      else         CPU_LED_DATA = 0;           ulval <<= 1;      CPU_LED_SRCLK = 1;    // Shift serial data into register   }      CPU_LED_LATCH = 1;  // Strobe data to output latch}

Perhaps you might also confirm the operation of the various bit manipulation macros.

 

Regards,

Mac

 

0 Kudos

980 Views
SARY
Contributor III

hi

thanks for the suggestion.I have changed the code it is working fine but the issue remains the same.with this also,all leds lit when i am setting single LED .I think that is some hadware issue,becoz this problem comes for the first time. But when I switch off  and starts again,it works fine.

0 Kudos

980 Views
bigmac
Specialist III

Hello Sary,

 

First, let's confirm the hardware connections you are using.  The code would be based on the following 'HC595 pins:

Pin 14 (device 1 only) = CPU_LED_DATA

Pin 13 (all devices) = CPU_LED_ENABLE

Pin 12 (all devices) = CPU_LED_LATCH

Pin 11 (all devices) = CPU_LED_SRCLK

Pin 10 (all devices) = tied to Vdd

Pin 9 (device 1) -> Pin 14 (device 2)

Pin 9 (device 2) -> Pin 14 (device 3)

 

On power-up, the shift register and latches may have arbitrary output state, so you will need to initialise by pulsing pin10 (SCLR) low, and then strobing pin 12 (RCK) to zero the output latches.  Alternatively, you might simply update the LEDs in the normal way, using a value of 0x000000, which should also zero the output latches (and presumably turn all LEDs off).

 

Now I am assuming that the LEDs states are not changing as the data is serial shifted into the register, but change only as a result of a positive transition of the CPU_LED_ LATCH signal, after the data shifting is complete.  The code does rely on the fact that the RCK pin is edge triggered, and would require some modification for transparent latch type.

 

Regards,

Mac

 

0 Kudos

980 Views
SARY
Contributor III

hi

  sorry for the late reply. i have made the same coonections as you said. I think the problem is due to master reset. i have made it permanently high .

    I think you are right i need to set it low first and then high to remove the flickering.

i willcheck this out and let u know.

thanks again.

SARY

0 Kudos