Last active
August 25, 2018 02:28
-
-
Save giljr/04e3cb51ab44a97bc13e0061659937d4 to your computer and use it in GitHub Desktop.
_43_CTC_AtmelStudio7_Code.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Project Ardu_Serie # 43 | |
* Working w/CTC Mode Part I - Atmega328p IC - Arduino MC | |
* | |
* Use: TIMER2 | |
* | |
* Objective: We need to flash an LED every 100 ms (10 Hertz). | |
*/ | |
#include <avr/io.h> | |
void timer2_init() | |
{ | |
TCCR2A |= (1 << WGM21) | (0 << WGM20); | |
TCCR2B |= (0 << WGM22) | (1 << CS22) | (1 << CS21) | (1 << CS20); | |
TCNT2 = 0; | |
OCR2A = 156; | |
} | |
int main(void) | |
{ | |
DDRB |= (1 << PINB5); | |
timer2_init(); | |
while(1) | |
{ | |
if (TIFR2 & (1 << OCF2A)) | |
{ | |
PORTB ^= (1 << PINB5); | |
} | |
TIFR2 |= (1 << OCF2A); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment