Hallo,
ich habe folgenden Code geschrieben:
1 | #include <avr/io.h>
|
2 | #include <inttypes.h>
|
3 | #ifndef F_CPU
|
4 | #define F_CPU 4000000UL
|
5 | #endif
|
6 | #include <util/delay.h>
|
7 | #include <stdint.h>
|
8 | #include <avr/interrupt.h>
|
9 | #include <stdlib.h>
|
10 |
|
11 | volatile uint16_t count;
|
12 | volatile uint16_t sec;
|
13 |
|
14 | int main()
|
15 | {
|
16 | DDRB=0b11111011;
|
17 | PORTB=0b11111011; //LEDs aus
|
18 |
|
19 | count=0;
|
20 | sec=0;
|
21 |
|
22 | while(1)
|
23 | {
|
24 | if((PINB & 0b00100000) == 0)
|
25 | {
|
26 | sei(); //Gobale Interrupts erlauben
|
27 |
|
28 | TCCR0B |= (1<<CS01); //CPU/64
|
29 | TCCR0B |= (1<<CS00); //auch... :-)
|
30 |
|
31 | TCCR0A |= (1<<WGM01); //CTC
|
32 |
|
33 | OCR0A = 100; //Setze Compare-register auf 100
|
34 |
|
35 | TIMSK |= (1<<OCIE0A); //aktivire compare-interrupt
|
36 |
|
37 | PORTB=0x00;
|
38 |
|
39 | while(1)
|
40 | {
|
41 | if(sec==60)
|
42 | PORTB |= (1<<PB3);
|
43 |
|
44 | if(sec==120)
|
45 | PORTB |= (1<<PB4);
|
46 |
|
47 | if(sec==180)
|
48 | {
|
49 | while(1)
|
50 | {
|
51 | PORTB |= (1<<PB2);
|
52 | _delay_ms(1.5);
|
53 | PORTB &= ~(1<<PB2);
|
54 | _delay_ms(1.5);
|
55 | }
|
56 | }
|
57 | }
|
58 | }
|
59 |
|
60 | }
|
61 |
|
62 | return 0;
|
63 | }
|
64 |
|
65 | ISR (TIMER0_COMPA_vect)
|
66 | {
|
67 | count++;
|
68 |
|
69 | if(count==625);
|
70 | {
|
71 | count=0;
|
72 | sec++;
|
73 | }
|
74 | }
|
das ganze soll nach einer Minute eine LED ausschalten (PB3), dann
nochmals eine Minute später eine weiter ausschalten(PB4). Wiederrum eine
Minute später wird die 3. LED ausgeschaltet.
Das funktioniert auch soweit, nur dass die Zeit nicht stimmt....
1min=1sec??? (circa) warum? - was mache ich falsch???
Ich benute den internen 4MHZ RC.
Doran
PS: Nutze AVR-Studio und den ATtiny2313