1 | //AT90S2313
|
2 |
|
3 |
|
4 | #include <inttypes.h>
|
5 | #include <avr/io.h>
|
6 | #include <avr/delay.h>
|
7 | #include <avr/interrupt.h>
|
8 | #include <avr/signal.h>
|
9 | #include <stdlib.h>
|
10 |
|
11 | #define CLK 10000000
|
12 |
|
13 |
|
14 | volatile unsigned int count=0;
|
15 |
|
16 | //Overflow-Interrupt (1Sekunde)
|
17 | SIGNAL(SIG_OUTPUT_COMPARE1A){
|
18 | GIMSK = (0<<INT0); //Interrupt0 deaktiv
|
19 | UDR = count; /count über rs232 ausgeben
|
20 | count = 0; //count zurücksetzen
|
21 | GIMSK = (1<<INT0); //Interrupt0 aktivieren
|
22 |
|
23 | }
|
24 |
|
25 | SIGNAL(SIG_INTERRUPT0){
|
26 |
|
27 | count++;
|
28 |
|
29 | }
|
30 |
|
31 |
|
32 | int main(void)
|
33 | {
|
34 |
|
35 | DDRB = 0xFF; // alles als Ausgang definieren
|
36 | PORTB = 0x00; // alles aus
|
37 |
|
38 | DDRD = 0x73;
|
39 | PORTD = 0x7F;
|
40 |
|
41 | delay_ms(20);
|
42 |
|
43 | UCR = (1 << TXEN | 1 << RXEN | 1 << RXCIE); //senden = an; Empfangen = an;
|
44 | //empafangsinterrupt = an
|
45 | UBRR = (CLK/(9600*16L)-1); //Baudrate setzen
|
46 |
|
47 |
|
48 |
|
49 | //16 Bit timer 1
|
50 | TCCR1B = (1<<CS10 | 0<<CS11 | 1<<CS12 | 1<<CTC1); //CLK/1024 | Compare match
|
51 |
|
52 | //Coampare auf 1 Sekunde (9765,625)
|
53 | OCR1AH = 38; //00100110 38
|
54 | OCR1AL = 37; //00100101 37
|
55 |
|
56 | TIMSK = (1<<OCIE1A); //Compare match aktiv
|
57 |
|
58 |
|
59 | //Interrupt0
|
60 | MCUCR = (1<<ISC01 | 1<<ISC00); //Int0 rising edge
|
61 | GIMSK = (1<<INT0); //Int0 aktiv
|
62 |
|
63 | sei(); //Globale Interrupts aktiv
|
64 |
|
65 | for (;;){} //Endlosschleife
|
66 |
|
67 | }
|