-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
89 lines (77 loc) · 1.96 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Ein kleiner Empfänger für DCF77
*
* Die empfangenen Bits werden auf den LEDs angezeigt
*/
#include <avr/interrupt.h>
#include <avr/io.h>
#include <stdlib.h>
void timer1_on();
void INT0_on(); //schaltet nur den INT0 "an"
uint16_t int_begin;
uint16_t signaldauer;
uint8_t signal;
uint8_t debug;
int main(void)
{
DDRC = 0xFF; //Port C auf Output setzen
timer1_on(); //schalte den Timer für den 1Hz Interrupt an
INT0_on();
sei();
debug = 0;
signal = 2;
while(42){
}
}
SIGNAL(SIG_OUTPUT_COMPARE1A){ //Timerinterrupt für LEDs
switch(signal){
case 2:
PORTC = 0xFF;
case 1:
PORTC = 0x0F;
case 0:
PORTC = 0xF0;
}
}
ISR(INT0_vect){
/**
switch(INT0){
case 1: //wenn der INT high ist
int_begin = TCNT1;
case 0: //wenn der INT low ist
if (TCNT1 > int_begin) // Wenn der Timerstand größer als der zuletzt "startende" Interrupt ist
signaldauer = TCNT1 - int_begin; //wie lange war der Interrupt?
if (TCNT1 <= int_begin) // wenn der Timer zwischen den INTs resettet wurde
signaldauer = int_begin - TCNT1; //wie lange war der Interrupt?
if ((signaldauer > 1475) && (signaldauer < 1650)){
signal = 0; // wenn das Signal ungefähr 100msec war -> 0
break;
}
if ((signaldauer > 3037) && (signaldauer < 3213)){
signal = 1; // wenn das Signal ungefähr 200msec war -> 1
break;
}
signal = 2; //wenn komisch
}
**/
if (debug == 1){
PORTC = 0x0F;
debug = 0;
}
else if (debug == 0){
PORTC = 0xF0;
debug = 1;
}
}
void timer1_on(){
TCCR1B |= (1 << WGM12); //CTC Modus
TCCR1B |= (1 << CS12); // Prescaler auf 1024
TCCR1B |= (1 << CS10); // Prescaler auf 1024
TIMSK |= (1 << OCIE1A); // Interrupt auslösen wenn CTC-Match
OCR1A = 15624; //Schwellenwert für CTC -> Interrupt 1Hz
}
void INT0_on(){
GICR |= (1 << INT0);
MCUCR |= (0 << ISC01);
MCUCR |= (1 << ISC00);
}