Hi, mir ist aufgefallen das bei mir die Delay Funktion nicht richtig funktioniert. Ich benutze das STK500 mit einem 8Mhz Quarz (Jumper richtig gesteckt / bei 4Mhz halb so schnell). Es sollen einfach nur jede Sekunde die LEDs abwechselnd an und aus gehen. Die LEDs blinken aber ca. 5x zu schnell. Woran könnte das liegen?
1 | #define F_CPU 8000000
|
2 | #include <avr/io.h> |
3 | #include <util/delay.h> |
4 | |
5 | int main(void){ |
6 | DDRB = 0xff; |
7 | PORTB = 0x00; |
8 | |
9 | uint8_t switcha = 0; |
10 | uint8_t counta = 0; |
11 | |
12 | while(1){ |
13 | counta++; |
14 | if(counta <= 100){ |
15 | _delay_ms(10); //max: 262,14 / 8 = 32,7675 ms |
16 | }
|
17 | else{ |
18 | if(switcha == 0){ |
19 | PORTB = 0x00; |
20 | switcha = 1; |
21 | }
|
22 | else{ |
23 | PORTB = 0xff; |
24 | switcha = 0; |
25 | }
|
26 | counta = 0; |
27 | }
|
28 | }
|
29 | return 0; |
30 | }
|