I am coding for a two digit seven segment display that counts up to 99, it is being called in a timer function that is fast enough so both digits are displayed at the same time with no flickering. However the display is not outputting the correct numbers I want it to for the case where the score is 0 to 9 it displays this on the right side of the SSD, however once it hits 10 it displays 11 rather than 10, so it is displaying the digit of the tens on both the right and left sides. I am not sure what the error is in my code, such that I need to fix so it does display the correct number for the ones on the right hand side. I am getting the correct display for the tens digit on the left side though, so only issue is the right side.
// 0 = right digit; 1 = left digit.
volatile uint8_t seven_seg_cc = 0;
void seven_segment_display(){
uint8_t score = get_score();
seven_seg_cc = 1 ^ seven_seg_cc;
if (score < 10){
PORTC = seven_segment_display_one[score];
}
else if(score >= 10){
if(seven_seg_cc == 0){
//Display right dig
PORTC = seven_segment_display_one[(score/10)%10];
}else{
//Display left dig
PORTC = seven_segment_display_one[score/10];
}
PORTA = (seven_seg_cc << DDRA4);
}
}
You need the modulus alone for the rightmost digit
if(seven_seg_cc == 0){
//Display right dig
//PORTC = seven_segment_display_one[(score/10)%10];
PORTC = seven_segment_display_one[score%10];
}else{
//Display left dig
PORTC = seven_segment_display_one[score/10];
}