I am trying to make a countdown timer using an ATmega32 clocked at 8 MHz.
I want to use the ATmega timer to start a countdown for 8 minutes when the switch is pressed and the output should turn on for 8 minutes and when the countdown hits zero the output should turn off and the countdown returning back to zero. (All this I want to show on a 16*2 LCD). I know that I have to use a timer for that, but I am really not sure on how to do it. Any suggestions?
Is creating this much long delay from an AVR timer possible or not?
Please don't be angry with me(I don't want to disrespect you people by answering my own question).I had tried to solve my problem myself and I had achieved this, this code works thanks for your valuable time to answer my questions. I have posted the code so that new people can benefit from it. Thanks for your time.
volatile uint16_t second_count = 0;
void init_timer1(void);
void init_timer1()
{
TCCR1B |= (1<<WGM12);//CTC mode
TCNT1 = 0;//initializing timer
OCR1A = 31249;//preloading timer so that it can count with 1 sec
TIMSK |= (1<<OCIE1A);//Timer compare A Match interrupt
TCCR1B |= (1<<CS12);//Starting timer and clock prescaler(256)
}
ISR(TIMER1_COMPA_vect)
{
second_count++;
if(second_count == 180)//turing the output on for 180 seconds on power on
{
PORTD |= (1<<PD6);
}
else
{
PORTD &= ~(1<<PD6);
second_count = 0;
}
}
int main(void)
{
init_timer1();
sei();
DDRD = 0xff;
PORTD = 0x00;
DDRB = 0x00;
PORTB = 0xff;
while(1)
{
}
}