1 | /
|
2 | * Header */
|
3 | #include <avr/io.h>
|
4 | #include <avr/interrupt.h>
|
5 | #include <util/delay.h>
|
6 | /* Defines */
|
7 | #define BAUD 0x0019 // 38.4kbaud @ 16 Mhz
|
8 |
|
9 |
|
10 |
|
11 | /* Prototypes */
|
12 | void USART_Init(void);
|
13 | void My_Init(void);
|
14 | void USART_Transmit(unsigned char datu);
|
15 | void ConfigInCapture1(void);
|
16 |
|
17 |
|
18 | /* Variables */
|
19 | unsigned char risel;
|
20 | unsigned char riseh;
|
21 | unsigned char zindex;
|
22 | unsigned char daten[81];
|
23 |
|
24 |
|
25 | int main(void)
|
26 | {
|
27 |
|
28 | My_Init();
|
29 |
|
30 | PORTA=0x01; // Led nach Reset an
|
31 | _delay_ms(2000);
|
32 | PORTA=0x00;
|
33 | _delay_ms(1000);
|
34 |
|
35 | USART_Init();
|
36 | ConfigInCapture1();
|
37 | sei();
|
38 |
|
39 |
|
40 |
|
41 | while(1)
|
42 | {
|
43 | for(unsigned char n=0;n<80;n++) // funktioniert 1 bis 80
|
44 | {
|
45 | USART_Transmit(daten[n]);
|
46 | }
|
47 |
|
48 |
|
49 | USART_Transmit(daten[0]); // Funktioniert nicht !!! 81
|
50 | USART_Transmit(daten[1]); // Warum ?
|
51 | USART_Transmit(daten[2]);
|
52 | USART_Transmit(daten[3]); // bis 84
|
53 |
|
54 | if(daten[0]!=0) // Warum geht der Zugriff nicht ?
|
55 | {
|
56 | PORTA=0x01; // Led an
|
57 | }
|
58 |
|
59 | _delay_ms(1000);
|
60 | }
|
61 | return 0;
|
62 | }
|
63 |
|
64 |
|
65 | ISR(TIMER1_CAPT_vect)
|
66 | {
|
67 | // Wert auslesen
|
68 | risel = ICR1L;
|
69 | riseh = ICR1H;
|
70 |
|
71 | if(zindex<=80)
|
72 | {
|
73 |
|
74 | daten[zindex]=riseh;
|
75 | zindex++;
|
76 | daten[zindex]=risel;
|
77 | zindex++;
|
78 | }
|
79 | else
|
80 | {
|
81 | TIMSK=0; // Capture AUS
|
82 | TIFR = (1<<ICF1);
|
83 | }
|
84 |
|
85 | TCCR1B ^=(1<<ICES1); // Flanke umschalten
|
86 | }
|
87 |
|
88 |
|
89 | void ConfigInCapture1(void)
|
90 | {
|
91 | TCCR1A = 0; // normal mode, keine PWM Ausgänge
|
92 | TCCR1B = (1<<ICES1)|(1<<CS01)|(1<<CS11);
|
93 | TIMSK |= (1<<TICIE1); //fallendeflanke // input-capture Interrupt aktivieren
|
94 | TIFR = (1<<ICF1);
|
95 | }
|
96 |
|
97 |
|
98 | void My_Init(void)
|
99 | {
|
100 | DDRA=0x01; //Anzeigeausgang
|
101 | DDRD=0x80; // Spannung Tempsens
|
102 | PORTD=0x80;// Spannung Tempsens
|
103 | zindex=0;
|
104 | for(unsigned char n=0;n<80;n++)
|
105 | {
|
106 | daten[n]=0;
|
107 | }
|
108 | }
|
109 |
|
110 |
|
111 |
|
112 | /* USART initialisieren */
|
113 | void USART_Init(void)
|
114 | {
|
115 | //8bit - 1 Stopbit
|
116 | UCSRB |= (1<<TXEN)|(1<<RXEN)|(1<<RXCIE);
|
117 | UCSRC |= (1<<URSEL)|(3<<UCSZ0);
|
118 | UBRRH = (unsigned char)(BAUD>>8); //Einstellen Baudrate
|
119 | UBRRL = (unsigned char)BAUD; //Einstellen Baudrate
|
120 | }
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | /* Senden */
|
126 | void USART_Transmit(unsigned char datu)
|
127 | {
|
128 | while ( !(UCSRA & (1<<UDRE)) );
|
129 | UDR = datu;
|
130 | }
|
131 |
|
132 |
|
133 | .....................................................................
|
134 | Nur zur Info
|
135 |
|
136 |
|
137 |
|
138 | > "make.exe" all
|
139 |
|
140 | -------- begin --------
|
141 | avr-gcc (WinAVR 20100110) 4.3.3
|
142 | Copyright (C) 2008 Free Software Foundation, Inc.
|
143 | This is free software; see the source for copying conditions. There is NO
|
144 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
145 |
|
146 |
|
147 | Size before:
|
148 | AVR Memory Usage
|
149 | ----------------
|
150 | Device: atmega16
|
151 |
|
152 | Program: 470 bytes (2.9% Full)
|
153 | (.text + .data + .bootloader)
|
154 |
|
155 | Data: 84 bytes (8.2% Full)
|
156 | (.data + .bss + .noinit)
|
157 |
|
158 |
|
159 |
|
160 |
|
161 | Compiling C: main.c
|
162 | avr-gcc -c -mmcu=atmega16 -I. -gdwarf-2 -DF_CPU=16000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=./main.lst -std=gnu99 -MMD -MP -MF .dep/main.o.d main.c -o main.o
|
163 |
|
164 | Linking: main.elf
|
165 | avr-gcc -mmcu=atmega16 -I. -gdwarf-2 -DF_CPU=16000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.o -std=gnu99 -MMD -MP -MF .dep/main.elf.d main.o --output main.elf -Wl,-Map=main.map,--cref -lm
|
166 |
|
167 | Creating load file for Flash: main.hex
|
168 | avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock main.elf main.hex
|
169 |
|
170 | Creating load file for EEPROM: main.eep
|
171 | avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
|
172 | --change-section-lma .eeprom=0 --no-change-warnings -O ihex main.elf main.eep || exit 0
|
173 |
|
174 | Creating Extended Listing: main.lss
|
175 | avr-objdump -h -S -z main.elf > main.lss
|
176 |
|
177 | Creating Symbol Table: main.sym
|
178 | avr-nm -n main.elf > main.sym
|
179 |
|
180 | Size after:
|
181 | AVR Memory Usage
|
182 | ----------------
|
183 | Device: atmega16
|
184 |
|
185 | Program: 470 bytes (2.9% Full)
|
186 | (.text + .data + .bootloader)
|
187 |
|
188 | Data: 84 bytes (8.2% Full)
|
189 | (.data + .bss + .noinit)
|
190 |
|
191 |
|
192 |
|
193 | -------- end --------
|
194 |
|
195 |
|
196 | > Process Exit Code: 0
|
197 | > Time Taken: 00:01
|