Hallo,
Ich habe einen ATmega32 und versuche diesen eine Spannung auswerten zu
lassen. Dazu benutze eine Funktion aus dem AVR-gcc-Tutorial.
1 | uint16_t ReadChannel(uint8_t mux) {
|
2 |
|
3 | uint8_t i;
|
4 | uint16_t result;
|
5 |
|
6 | ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);
|
7 |
|
8 | ADMUX = mux;
|
9 | ADMUX &= 0x3F;
|
10 |
|
11 |
|
12 | ADCSRA |= (1<<ADSC);
|
13 |
|
14 | while ( ADCSRA & (1<<ADSC) ) {
|
15 | ;
|
16 | }
|
17 |
|
18 | result = ADCW;
|
19 |
|
20 | result = 0;
|
21 |
|
22 | for( i=0; i<4; i++ ) {
|
23 | ADCSRA |= (1<<ADSC);
|
24 |
|
25 | while ( ADCSRA & (1<<ADSC) ) {
|
26 | ;
|
27 | }
|
28 |
|
29 | result += ADCW;
|
30 | }
|
31 |
|
32 | ADCSRA &= ~(1<<ADEN);
|
33 |
|
34 | result /= 4;
|
35 |
|
36 | return result;
|
37 | }
|
Wenn ich diese ganz normal in die main-datei schreibe, lässt sich diese
ohne Fehlermeldung ausführen. Lagere ich sie aber in die Datei
adc-routines.c aus und erstelle auch den entsprechenden Header-File,
1 | uint16_t ReadChannel(uint8_t);
|
bekomme ich folgenden Output:
> "make.exe" all
-------- begin --------
avr-gcc (GCC) 4.2.2 (WinAVR 20071221)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
Compiling C: main.c
avr-gcc -c -mmcu=atmega8 -I. -gdwarf-2 -DF_CPU=10000000UL -Os
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall
-Wstrict-prototypes -Wa,-adhlns=./main.lst -std=gnu99 -Wundef -MMD -MP
-MF .dep/main.o.d main.c -o main.o
In file included from main.c:3:
./lcd-routines.h:15:1: warning: "F_CPU" redefined
<command-line>: warning: this is the location of the previous definition
main.c: In function 'main':
main.c:22: warning: implicit declaration of function 'itoa'
main.c:23: warning: passing argument 1 of 'lcd_string' from incompatible
pointer type
Compiling C: adc-routines.c
avr-gcc -c -mmcu=atmega8 -I. -gdwarf-2 -DF_CPU=10000000UL -Os
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall
-Wstrict-prototypes -Wa,-adhlns=./adc-routines.lst -std=gnu99 -Wundef
-MMD -MP -MF .dep/adc-routines.o.d adc-routines.c -o adc-routines.o
adc-routines.c:1: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'ReadChannel'
make.exe: *** [adc-routines.o] Error 1
> Process Exit Code: 2
Verstehe nicht, was an meinem Programm falsch sein soll. Schon mal im
Vorraus dankbar für Hilfe.