Skip to main content

05 Experiment

Toggle the LED every second using Timer interrupt.

Source and description

http://sincgrid.in/avr-tutorials/avr-tutorial-experiment-5/

http://sincgrid.in/avr-tutorials/avr-tutorial-experiment-5/
#include <avr/io.h>
#include <avr/interrupt.h>

#define LED PD4

ISR (TIMER1_OVF_vect) // Timer1 ISR
{
PORTD ^= (1 << LED);
TCNT1 = 49916; // for 1 sec at 16 MHz
}

int main()
{
DDRD = (0x01 << LED); //Configure the PORTD4 as output

TCNT1 = 49916; // for 1 sec at 16 MHz

TCCR1A = 0x00;
TCCR1B = (1<<CS10) | (1<<CS12);; // Timer mode with 1024 prescler
TIMSK1 = (1 << TOIE1) ; // Enable timer1 overflow interrupt(TOIE1)
sei(); // Enable global interrupts by setting global interrupt enable bit in SREG

while(1)
{

}
}