Trouble Using a 74HC595 Shift Register to display numbers on 2x 7 segment displays

Thread Starter

jonaas18

Joined Apr 4, 2019
67
Hi there!

I'm making a project in which I'm building the PONG game. I've created the code necessary to program the matrix and the game itself (ball, players, etc.) however I'm running into some trouble figuring out what's wrong with my players' scores (everything else is going as expected).

I'm using an ATMega32 with 1x 74HC595 Shift Register and 2x 74LS47N chips. I built this circuit (the shift reg + decoders + 7 segment) like shown in the image below. I also used this code I found online (strictly, everything's the same):

C:
    #define CLK   0                                                                                                                    // PB0: Shift Register pin 11 (Clock).
    #define S_IN  1                                                                                                                    // PB1: Shift Register pin 14 (Data).
    #define LATCH 2   
        DDRB = 0x0F;                                                                                                                // PB0 - PB3 as outputs (buzzer + shift register) and last 4 pins defined as inputs (switches).


void shift_data(uint8_t data)
{
    uint8_t i;
    uint8_t bit;

    PORTB &= ~(1 << LATCH); //deactivate latch output

    for (i = 0; i < 8; i++)
    {
        PORTB &= ~(1 << S_IN);
        PORTB &= ~(1 << CLK);

        if (data & (1 << i))
            bit = 0x01;
        else
            bit = 0x00;

        PORTB |= (bit << S_IN);
        PORTB |= (1 << CLK);
    }

    PORTB &= ~(1 << CLK);  //set clock to zero
    PORTB |= (1 << LATCH); //activate latch output
}

void update_score(uint8_t score_p1, uint8_t score_p2)
{
    shift_data((score_p2 & 0x0F) | ((score_p1 & 0x0F) << 4));
}

I call this function right before the game starts (after inic) and update it with the line: update_score(0, 0);
Then, whenever a goal is scored, I use the line: update_score(score1,score2); beeing score1 and score2 counters that increment when the ball enters the net.

I already re-checked my circuitry and it all seems fine (though a bit clustered).

What happens is that instead of displaying the numbers properly (0,1,2,.....9), it shows some numbers right (1, 3, 4) but others wrong (0 looks like a 2 in one of the displays; 0 looks like an 8 in the other display; 7 has a lighted on segment which shouldn't be lighted on, etc.).

I'll also leave you with the 7 Segment Display pinout. Any help would be appreciated as the work is due to deliver this week. Just missing this and can't understand the problem.

1577944214494.png

1577944195543.png
 
Last edited:

dl324

Joined Mar 30, 2015
9,985
Any help would be appreciated as the work is due to deliver this week. Just missing this and can't understand the problem.
What do you think the 74LS47 are doing while your you're shifting data in to the shift register?
EDIT: corrected typo

Is this school work?
 
Last edited:

Ian Rogers

Joined Dec 12, 2012
699
What do you think the 74LS47 are doing while your shifting data in to the shift register?
Shouldn't be doing anything until RCK is clocked.. But you are right... The latch is just needed at the end of the 8 bits are clocked in... I would just pulse portb pin 2 after all bits are done..
 

Chris65536

Joined Nov 11, 2019
164
If it's displaying invalid characters, then the problem is probably in the connections from the 7447s to the 7 segment displays. Double check the pinout on those displays. They are sometimes goofy.
 
Top