Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@holachek
Created August 10, 2012 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save holachek/3310612 to your computer and use it in GitHub Desktop.
Save holachek/3310612 to your computer and use it in GitHub Desktop.
Toggle PD6 every second using AVR timers
#define LEDPORT PORTD
#define LEDBIT PD6
#define LEDDDR DDRD
#include <avr/io.h>
int main (void)
{
LEDDDR |= (1 << LEDBIT); // set LED pin as an output
TCCR1B |= ((1 << CS10) | (1 << CS11)); // configure timer prescaling
for(;;)
{
if (TCNT1 >= 15624) // when the timer counts one second
{
LEDPORT ^= (1 << LEDBIT); // toggle the LED
TCNT1 = 0; // and reset the timer value
}
}
return 0; // the program executed successfully
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment