Skip to content

Instantly share code, notes, and snippets.

@Xplorer001
Last active June 14, 2022 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Xplorer001/c60da4750e5cb67206a6 to your computer and use it in GitHub Desktop.
Save Xplorer001/c60da4750e5cb67206a6 to your computer and use it in GitHub Desktop.
/*
| Example part of AVR Tutorial Series @ Explore Embedded
| To read the detailed tutorial visit:
| http://exploreembedded.com/wiki/5.AVR_Timer_programming
*/
#include<avr/io.h>
#include <util/delay.h>
#define LED PD4
int main()
{
DDRD |= (1<<LED) ; //configure led as outpout
TCCR1B = (1<<CS10) | (1<<CS12); //set the pre-scalar as 1024
OCR1A = 1562; //100ms delay
TCNT1 = 0;
while(1)
{
//If flag is set toggle the led
while((TIFR & (1<<OCF1A)) == 0);// wait till the timer overflow flag is SET
PORTD ^= (1<< LED);
TCNT1 = 0;
TIFR |= (1<<OCF1A) ; //clear timer1 overflow flag
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment