ATmega88 @ 8MHz Timer Normal Mode
This file contains 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
/* timer_normal_mode_01.c ATmega88 @ 8MHz */ | |
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#define preload_value 64536 // Timer1 Vorladewert | |
void init_timer_1 (void) | |
{ | |
TCCR1A = 0x00; // Timer1 Normal Mode (Mode 0) | |
TCCR1B = (1<<CS11); // Prescaler = 8 -> 8Mhz/8 = 1MHz | |
TIMSK1 = (1<<TOIE1); // Timer1 overflow interrupt enable | |
TCNT1 = preload_value; // Timer1 Zählregister vorladen | |
} | |
int main(void) | |
{ | |
DDRB = 0xFF; // PORTB Richtungsregister = Ausgang | |
init_timer_1(); // Timer 1 initialisieren | |
sei(); // Interrupts einschalten | |
while(1) | |
{ | |
asm ("NOP"); // Nichts tun | |
} | |
} | |
ISR(TIMER1_OVF_vect) // Timer1 Interrupt wird alle 1ms ausgeführt | |
{ | |
TCNT1 = preload_value; // Timer1 erneut vorladen | |
PORTB ^= (1<<PB3); // PB3 toggeln (1kHZ Takt erzeugen) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment