Skip to content

Instantly share code, notes, and snippets.

@avr-programmierung
Created May 14, 2019 11:19
Show Gist options
  • Save avr-programmierung/cc1f4bdaf380c5fe3366603fe72de68b to your computer and use it in GitHub Desktop.
Save avr-programmierung/cc1f4bdaf380c5fe3366603fe72de68b to your computer and use it in GitHub Desktop.
ATmega88 @ 8MHz Timer CTC-Mode
/* timer_ctc_mode_01.c ATmega88 @ 8MHz */
#include <avr/io.h>
#include <avr/interrupt.h>
#define LED (1<<PB3) // LED auf Portpin B3
int main(void)
{
DDRB |= (1<<PB3); // Portpin B3 = output
TCCR1B |= (1 << CS12); // Vorteiler auf 256 und Timer start
TCCR1B |= (1 << WGM12); // Mode 4, CTC on OCR1A
OCR1A = 31249; // Compare match auf 31249 setzen
TIMSK1 |= (1 << OCIE1A); // Interrupt bei compare match aktivieren
sei(); // enable interrupts
while(1)
{
asm ("NOP"); // Nichts tun
}
}
ISR (TIMER1_COMPA_vect) // Timer1 Compare Match Interrupt
{
PORTB ^= LED; // LED im Sekundentakt toggeln lassen
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment