1 | #include <avr/io.h>
|
2 | #include <avr/interrupt.h>
|
3 | #include <avr/wdt.h>
|
4 | #include <stdint.h>
|
5 | #include <avr/sleep.h>
|
6 |
|
7 |
|
8 | int main(void)
|
9 | {
|
10 | //int schalter;
|
11 | int schalter = 0;
|
12 |
|
13 | DDRB |= (1 << PB1); // LED von VCC auf Portpin; low-active
|
14 | PORTB |= (1 << PB1); // PB1 auf Ausgang
|
15 | DDRB &= ~(1 << PB2); // Bit löschen; damit PB2 Eingang
|
16 | PORTB |= (1 << PB2); // Taster an PB2 mit internem Pull-up (auf GND)
|
17 |
|
18 | // divide system clock with "Clock Prescale Register"
|
19 | //Faktor 8; 1MHz
|
20 | CLKPR = (1<<CLKPCE) | (1<<CLKPS1) | (1<<CLKPS0);
|
21 | //CLKPR = 0x83; // Wird hier 1 MHz erreicht oder 125 kHz?????
|
22 |
|
23 | wdt_disable(); //deaktiviern des Watchdog Timers
|
24 |
|
25 | sei(); // Zulassung von Interrupts
|
26 |
|
27 | while(1)
|
28 | {
|
29 | if((!(PINB & (1 << PINB2))) && schalter == 0) // Taster gedrückt (log. 0) und Variabe Schalter = 0
|
30 | {
|
31 | //while(!(PINB & (1 << PINB2)))
|
32 | if((PINB & (1 << PINB2)) && schalter == 0) // Taster losgelassen (log. 1)
|
33 | {
|
34 | PORTB &= ~(1 << PB1); // PB1 auf 0 - LED leuchtet
|
35 | }
|
36 | schalter = 1;
|
37 | }
|
38 |
|
39 | if((!(PINB & (1 << PINB2))) && schalter == 1) // Taster gedrückt (log. 0) und Variable Schalter = 1
|
40 | {
|
41 | //while(!(PINB & (1 << PINB2)))
|
42 | if((PINB & (1 << PINB2)) && schalter == 0) // Taster losgelassen (log. 1)
|
43 | {
|
44 | PORTB |= (1 << PB1); // PB1 auf 1 - LED erlischt
|
45 | }
|
46 | schalter = 0;
|
47 | }
|
48 | return 0;
|
49 | }
|