title: Multiplexing seven segment display on AVR Atmega324A
body: <p>I've been stuck on this all day, I'm trying to create a count down timer using two seven segment displays. I want it to start at 20 and count down to zero. While 10&lt; I only want to have the left display on(i.e no 0 in the tens place). I'm using an Atmega 324A. I have all of port C connected to the display segments and am using PIND0 to toggle between the two. Here is what I have so far.</p>
  
  <pre><code>#include &lt;avr/io.h&gt;
  #include&lt;util/delay.h&gt;
  
  
  int main(void) {
  
      int prescale = (8000000/8)/1000-1;
      int digit = 1;
      uint8_t display;
      int seven_seg = {0x3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0C07,0X7F,0X6F};
      // Set OC1 to output
      DDRD = (1&lt;&lt;0);
      DDRC = 0xFF;
  
      OCR1A = prescale;
      //clear counter on compare match
      TCCR1A = (0&lt;&lt;COM1A1) | (1&lt;&lt;COM1A0);
      //Set Prescale and CTC Mode
      TCCR1B =  (0&lt;&lt;CS12) | (1&lt;&lt;CS11) | (0&lt;&lt;CS10) | (0&lt;&lt;WGM13) | (1&lt;&lt;WGM12);
  
  
      while(1) {
  
              display++;
              if(display&gt;50) display = 0;
              for (i = 250; i&gt;0; i--){        
              PORTD ^= 0&lt;&lt;PIND0;
              PORTC = seven_seg[display%10];                
              PORTD ^= 1&lt;&lt;PIND0;
              _delay_ms(100);
              for (i = 250; i&gt;0; i--){        
                  PORTD ^= 1&lt;&lt;PIND0;
                  PORTC = seven_seg[display/10];                
                  PORTD ^= 0&lt;&lt;PIND0;
                  _delay_ms(100);
               }
              }
          while((TIFR1 &amp; (1&lt;&lt;OCF1A)) == 0) {}
  
          TIFR1 &amp;= (1 &lt;&lt; OCF1A);  
  
      }
  }
  </code></pre>
  
  <p>All this does is set both displays to 0. Do I need another for loop to iterate through the seven_seg[] array while it's doing this? really not sure how to tackle this one. Any help would be great.</p>