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):
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.


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.


Last edited: