1 | #include <avr/io.h>
|
2 | #include <avr/interrupt.h>
|
3 | #include <avr/sleep.h>
|
4 |
|
5 | int LEDFlag;
|
6 |
|
7 |
|
8 | ISR(TIM0_COMPA_vect) {
|
9 | if(LEDFlag==1) {
|
10 | PORTB &= ~_BV(PB4); // PB2 is low
|
11 | LEDFlag=0;
|
12 | } else {
|
13 | // disable modulated signal
|
14 | PORTB |= _BV(PB4); // PB2 is hi
|
15 | LEDFlag=1;
|
16 | }
|
17 | }
|
18 |
|
19 | ISR(PCINT0_vect){
|
20 | LEDFlag=1;
|
21 | }
|
22 |
|
23 |
|
24 | main()
|
25 | {
|
26 | // setup waveform generation to 36kHz on timer 0
|
27 | TCCR0A |= _BV(WGM01); // clear timer on compare match
|
28 | TCCR0B |= _BV(CS00); // timer source is system clock
|
29 | OCR0A = 108; // output compare value for 36kHz @ 8 MHz
|
30 |
|
31 | TIMSK |= _BV(OCIE0A);
|
32 |
|
33 | // output compare pin to output mode, low level
|
34 | DDRB = _BV(PB4); // port PB2 as output
|
35 | PORTB |= _BV(PB2); // PB2 is hi pullup aktivieren
|
36 |
|
37 | MCUCR &= ~_BV(ISC00); // levelgesteuerter Interrupt an INT0
|
38 | MCUCR &= ~_BV(ISC01);
|
39 |
|
40 | sei();
|
41 |
|
42 | while(1) {
|
43 | //GIMSK |= (1 << INT0);
|
44 | //TIMSK &= ~_BV(OCIE0A);
|
45 | //GICR |= (1 << INT0); // externen Interrupt freigeben
|
46 |
|
47 | set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
48 | sleep_mode(); // in den Schlafmodus wechseln
|
49 |
|
50 | // hier wachen wir wieder auf
|
51 | //GICR &= ~(1 << INT0); // externen Interrupt sperren
|
52 | // WICHTIG! falls der externe LOW Puls an INT0
|
53 | // sehr lange dauert
|
54 |
|
55 |
|
56 | }
|
57 |
|
58 | }
|