Skip to content

Instantly share code, notes, and snippets.

@raghavendrahassy
Last active July 7, 2022 08:20
Show Gist options
  • Save raghavendrahassy/cbf6fd9571ac6e8fc0c5 to your computer and use it in GitHub Desktop.
Save raghavendrahassy/cbf6fd9571ac6e8fc0c5 to your computer and use it in GitHub Desktop.
#include<avr/io.h>
#include<avr/interrupt.h>
#define LED PD4
ISR (TIMER1_OVF_vect) // Timer1 ISR
{
PORTD ^= (1 << LED);
TCNT1 = 63974; // for 1 sec at 16 MHz
}
int main()
{
DDRD = (0x01 << LED); //Configure the PORTD4 as output
TCNT1 = 63974; // for 1 sec at 16 MHz
TCCR1A = 0x00;
TCCR1B = (1<<CS10) | (1<<CS12);; // Timer mode with 1024 prescler
TIMSK = (1 << TOIE1) ; // Enable timer1 overflow interrupt(TOIE1)
sei(); // Enable global interrupts by setting global interrupt enable bit in SREG
while(1)
{
}
}
@wallem89
Copy link

  1. On line 1 and 2 it would be nicer to add a space between '#include' and '<'
  2. On line 19 the second semicolomn should be removed.
  3. On line 20 it would be nicer te remove the space before the semicolomn.

@Hsu1685
Copy link

Hsu1685 commented Oct 5, 2020

It looks like the TCNT1 value you are setting is not quite correct for the comment.

  1. On line 9 it should be "// for 0.1 sec at 16 MHz" instead of "1 sec".
  2. On line 16 it should be "// for 0.1 sec at 16 MHz" instead of "1 sec".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment