Total Pageviews

Tuesday 22 August 2017

Count Down Timer using ATMega 8


Count Down Timer using ATMega 8

            A countdown timer is a down counter that counts from a specified time to 00:00. It is used in many devices such as washing machine, televisions, microwave ovens, etc. This countdown timer has three states: the running state where it counts down, the pause state where it displays the paused time and the reset state to set the countdown. The countdown is displayed on a set of four seven segment displays using the ATMega 8 microcontroller. A buzzer beeps when the countdown gets over.












   

  I/O Port Map: 






























Snippets of Code :

     1)      To enable INT0 and INT1 :
          GICR =(1<<INT1)|(1<<INT0); MCUCR =0b00001010; sei();

         2)      To perform ADC :
      ADCSRA = 0x8F|(1<<ADFR);  ADMUX = 0xC0|ADC_Channel;  sei();  ADCSRA |= 1<<ADSC;

         3)      To initialize Timer 1:
      TCCR1B |= (1 << CS12)|(1<<CS10); TCNT1 =_________;TIMSK|=(1<<TOIE1); sei();

         4)      To initialize Timer 0:
      TCCR0 = (1 << CS02)|(1 << CS00);  TCNT0 =0;     TIMSK |= (1 << TOIE0); sei();

         5)      To select the various digits in 4 -  Seven Segment Display :
          Digit 1 : PORTB = 0b00001110;   // Common Anode
          Digit 2 : PORTB = 0b00001101;
          Digit 3 : PORTB = 0b00001011;
          Digit 4 : PORTB = 0b00000111;

         6)      Interrupt Service Routine :
          INT 0    :    ISR ( INT0_vect )
          INT 1    :    ISR ( INT1_vect )
          ADC     :    ISR ( ADC_vect )
          Timer 0 :    ISR ( TIMER0_OVF_vect )
          Timer 1 :    ISR ( TIMER1_OVF_vect )


   Psuedo Code :

    main()
  {
      //  Initialize the I/O as INPUT or OUTPUT
      //   Use PULL – UP mode for Inputs
      //   Initialize ADC Channel
      while(1)
      {
          // Continuously display values on Seven Segment Display
          // If time = 00:00 , blink and beep
       }
  }

   ISR ( TIMER1_OVF_vect )
  {  //  Decrement seconds value by 1
      //   Initialize Timer 1 again 
   }

   ISR ( ADC_vect)
  {   // Store the ADC0 channel value which corresponds to Minutes
       // Store the ADC1 channel value which corresponds to Seconds
       //  Initialize ADC again
   }

  Prototype:          

  




        Video :