Hallo,
Ich wollte mal einen Timer zum laufen bringen. Wenn ich meinen Code
richtig geschrieben hab, sollte PORTB relativ schnell blinken. PORTB
Leuchtet aber dauerhaft. Ich habe einen ATMega 8515 mit einem 8Mhz
Quarz. Hier der Code:
1 | #include <avr/io.h>
|
2 | #include <avr/interrupt.h>
|
3 | #define F_CPU 8000000UL
|
4 |
|
5 | int times, portstate;
|
6 |
|
7 | int main(void)
|
8 | {
|
9 | portstate = 0;
|
10 | DDRB = 0xFF;
|
11 | TCCR0 = (1<<CS01);
|
12 |
|
13 |
|
14 | TIMSK |= (1<<TOIE0);
|
15 |
|
16 |
|
17 | sei();
|
18 |
|
19 | while(1)
|
20 | {
|
21 |
|
22 | }
|
23 | }
|
24 |
|
25 | #ifndef TIMER0_OVF_vect
|
26 | #define TIMER0_OVF_vect TIMER0_OVF0_vect
|
27 | #endif
|
28 |
|
29 | ISR (TIMER0_OVF_vect)
|
30 | {
|
31 | times++;
|
32 | /* Interrupt Aktion alle
|
33 | (1000000/8)/256 Hz = 488,28125 Hz
|
34 | bzw.
|
35 | 1/488,28125 s = 2,048 ms
|
36 | */
|
37 | if(times = 100){
|
38 | times = 0;
|
39 | if(portstate = 0){
|
40 | PORTB = 0x00;
|
41 | portstate = 1;
|
42 | }else{
|
43 | PORTB = 0xFF;
|
44 | portstate = 0;
|
45 | }
|
46 | }
|
47 | }
|
Ich hoffe ihr könnt mir helfen.