Rev 112 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 112 | Rev 114 | ||
---|---|---|---|
1 | 1 | ||
2 | #include <avr/io.h> |
2 | #include <avr/io.h> |
3 | #include <avr/interrupt.h> |
3 | #include <avr/interrupt.h> |
4 | #include "main.h" |
4 | #include "main.h" |
5 | #include "timer.h" |
5 | #include "timer.h" |
6 | 6 | ||
7 | volatile uint8_t timer; |
7 | volatile uint8_t timer; |
8 | volatile uint8_t counter, counter2; |
8 | volatile uint8_t counter, counter2; |
9 | volatile uint8_t key; |
9 | volatile uint8_t key; |
10 | volatile uint8_t rs232_timer; |
10 | volatile uint8_t rs232_timer; |
11 | 11 | ||
12 | 12 | ||
13 | ISR(SIG_OUTPUT_COMPARE0) // Timer-Interrupt (100 Hz) |
13 | ISR(SIG_OUTPUT_COMPARE0) // Timer-Interrupt (100 Hz) |
14 | { |
14 | { |
15 | if (counter > 0) |
15 | if (counter > 0) |
16 | counter --; |
16 | counter --; |
17 | else |
17 | else |
18 | { |
18 | { |
19 | counter = 10; |
19 | counter = 10; |
20 | key = (~PINA >> 4) & 0x0F; |
20 | key = (~PINA >> 4) & 0x0F; |
21 | counter2 ++; |
21 | counter2 ++; |
22 | } |
22 | } |
23 | 23 | ||
24 | if (timer > 0) |
24 | if (timer > 0) |
25 | timer --; |
25 | timer --; |
26 | 26 | ||
27 | if (rs232_timer > 0) |
27 | if (rs232_timer > 0) |
28 | rs232_timer --; |
28 | rs232_timer --; |
29 | 29 | ||
30 | } |
30 | } |
31 | 31 | ||
32 | void timer_init (void) |
32 | void timer_init (void) |
33 | { |
33 | { |
34 | TCCR0 = (1<<CS02)|(1<<CS00)|(1<<WGM01); // Prescaler 1024 |
34 | TCCR0 = (1<<CS02)|(1<<CS00)|(1<<WGM01); // Prescaler 1024 |
35 | OCR0 = 72; // Interrupt 100Hz für 7,372800 MHz-Quarz |
35 | // OCR0 = 72; // Interrupt 100Hz für 7,372800 MHz-Quarz |
- | 36 | ||
- | 37 | // OCR0 = (F_CPU / ( 100 * 2 * 1024)) -1 ; |
|
- | 38 | OCR0 = (F_CPU / ( 100L * 1024L)) ; |
|
- | 39 | ||
36 | TIMSK |= (1<<OCIE0); // Interrupt freigeben für OCR |
40 | TIMSK |= (1<<OCIE0); // Interrupt freigeben für OCR |
37 | } |
41 | } |
38 | 42 |