Moin Zusammen,
ich habe ein ganz kleines Programm. Dieses soll eine LED am ATMega8 Port
PB1 einschalten, wenn ein Taster am Eingang PC3 gedrückt wird und nach
10 Sekunden geht die LED wieder aus:
1 | #include <avr/io.h>
|
2 | #include <util/delay.h>
|
3 |
|
4 | void sleep(int milliseconds) {
|
5 | while (milliseconds > 0) {
|
6 | _delay_ms(1);
|
7 | milliseconds--;
|
8 | }
|
9 | }
|
10 |
|
11 | int main() {
|
12 | // initialize the cabin led
|
13 | DDRB = 0b11111111; // PORTB output for the LED
|
14 | // and the button
|
15 | PORTC |= 0b0001000; // enable pull up for PC3
|
16 |
|
17 | // blink the led 4 times
|
18 | DDRB |= (1<<PB1);
|
19 | sleep(1000);
|
20 | DDRB &= ~(1<<PB1);
|
21 | sleep(1000);
|
22 | DDRB |= (1<<PB1);
|
23 | sleep(1000);
|
24 | DDRB &= ~(1<<PB1);
|
25 | sleep(1000);
|
26 | DDRB |= (1<<PB1);
|
27 | sleep(1000);
|
28 | DDRB &= ~(1<<PB1);
|
29 |
|
30 |
|
31 | // and go...
|
32 | while(1) {
|
33 | // PC3 is low?
|
34 | if((PINC & 0b0001000)==0) {
|
35 | DDRB |= (1<<PB1);
|
36 | sleep(10000);
|
37 | }
|
38 |
|
39 | // finally make sure to turn off the led
|
40 | DDRB &= ~(1<<PB1);
|
41 | } // Main loop
|
42 | }
|
Der HW Aufbau ist dem Bild zu entnehmen und nicht besonders spektakulär.
Der ATMega hängt an 3 AA Batterien - die liefern ca. 4,09V laut
Voltmeter.
Ach ja, im Bild hing die LED noch an PD5 - ich hab sie aber testhalber
auf PB1 umgehängt.
Mein Problem ist nun: weder das Blinken zu Beginn, noch wenn ich den
Button drücke, funktioniert.
Kann mir einer sagen, was hier falsch läuft???
Danke schon einmal,
Christian