Counter Compare Match Interrupt zur Takterzeugung
Ver.1.0.
kner 2016
Main Page
Files
File List
File Members
start.cpp
Go to the documentation of this file.
1
18
#define F_CPU 1000000UL //1 MHz
19
#include <Arduino.h>
20
21
//#define DEBUG_LCD
22
#include "_debug.h"
23
24
25
#define OUTPUT PORTC0
26
void
setup()
27
{
28
DDRC = _BV(OUTPUT);
//OUTPUT as output
29
PORTC &= ~_BV(OUTPUT);
// clear pin
30
31
TCCR2A = 0; TCCR2B=0; cli();
// remove arduion config for timer2
32
//Timer2 im Compare Mode
33
// Prescaler = 1024
34
// external Input
35
ASSR = _BV(EXCLK);
//switch to external clock instead of ext. 32kHz crystal
36
ASSR |= AS2;
// switch to clock signal from extern
37
38
ASSR = 0;
// for debug only
39
40
TCCR2A = _BV(WGM21);
// Clear Timer on Compare Match MOde
41
TIMSK2 |= _BV(OCIE2A);
// Enable Compare Match Int. A
42
TCCR2B |= _BV(CS22)|_BV(CS21)|_BV(CS20);
// Prescal factor 1024; timer2 start
43
44
sei();
45
}
46
48
void
loop
()
49
{
50
uint8_t period = PINB;
51
period = 100;
//debug only
52
period = (period>>1)-1;
// pin toggles, we need half the period (and a small correction)
53
OCR2A = period;
54
55
}
57
ISR
(TIMER2_COMPA_vect){
58
PORTC ^= _BV(OUTPUT);
59
T(
"Done"
);
60
}
ISR
ISR(TIMER2_COMPA_vect)
Definition:
start.cpp:57
loop
void loop()
Definition:
start.cpp:48
Generated by
1.8.11