using multiple shift registers

by Muhammad Sufyan Raza   Last Updated April 15, 2019 10:25 AM

I am using Atmega128 and 8 shift registers 6D595 the ser_out of each register is connected to the next shift register's ser_in so they form a chain. There is no issue with the hardware it has been tested. I am using 4 16 bit variables to send data to shift registers. the problem that i am facing is that only once i am able to latch out the values only once .. For example if i send 4 variables as 0x0011,0xFF00,0x3c1d,0x1100 (they can be anything ) then i get the output on my 8 segment panel. but i am only able to update my registers only once . if i try to update them in a loop the program only shows the first value that i had sent to the shift register function

here is what i am doing in my shift out register

void shift_out(uint16_t data[4])
make latch pin HIGH
for(int x=0;x<3;x++)
{
      for(int i=0;i<16;i++) 
     { 
             set data pin according to data[x] 
             give a low pulse to clock pin then make it high
     }
}
give a low pulse to latch pin then make it high 

if i call this function once it works perfectly fine

but if i call it again with different values nothing happens

please help me i am not sure what else information i am supposed to share.. but i am willing to share anything.. Thanks in advance!!

Here is the complete function

void shift_out_data2(uint16_t data1,uint16_t data2,uint16_t data3,uint16_t data4) {

//PORTC |= (1<<(2));
//PORTC &= 0b11111011;
for(int i=0;i<16;i++)
{
    if(data1 & (1<<(i)))
    PORTC |= (1<<(3));
    else
    PORTC &= 0b11110111;

    PORTC &= 0b11101111;   //Clock Pin
    _delay_us(10);
    PORTC |= (1<<(4));     //Clock Pin

}

for(int i=0;i<16;i++)      //same for loop as above but for next data
{
    if(data2 & (1<<(i)))   
    PORTC |= (1<<(3));
    else
    PORTC &= 0b11110111;

    PORTC &= 0b11101111;
    _delay_us(10);
    PORTC |= (1<<(4));

}
for(int i=0;i<16;i++)        //same for loop as above but for next data
{
    if(data3 & (1<<(i)))
    PORTC |= (1<<(3));
    else
    PORTC &= 0b11110111;

    PORTC &= 0b11101111;
    _delay_us(10);
    PORTC |= (1<<(4));

}

for(int i=0;i<16;i++) //same for loop as above but for next data
{
    if(data4 & (1<<(i)))
    PORTC |= (1<<(3));
    else
    PORTC &= 0b11110111;

    PORTC &= 0b11101111;
    _delay_us(10);
    PORTC |= (1<<(4));

}
 PORTC |= 0b00000100;        //Latch Pin
 _delay_us(10);
 PORTC &= 0b11111011;}          //:Latch Pin 

I tried to add comments to it becomes readable ... i know its not an efficient code but its just for testing. Thanks!



Related Questions



Get more UARTs with a Shift Register?

Updated April 21, 2017 00:25 AM

Atmega88p with shift register 74hc595

Updated September 03, 2018 23:25 PM