Wie erwartet kamen viele Fehlermeldungen! :roll:
Es ist doch eine Funktion, oder? Wie ruf ich sie auf?
Muss ich was an der Headerdatei ändern?
Druckbare Version
Wie erwartet kamen viele Fehlermeldungen! :roll:
Es ist doch eine Funktion, oder? Wie ruf ich sie auf?
Muss ich was an der Headerdatei ändern?
Wenns schnell und einfach gehen soll:
neue Datei erstellen, Funktion rein kopieren
Vor die Funktion (mein Code) schreibst du eine Zeile davor:
Damit wird ein Prototyp der Funktion erstellt (kommt normalerweise in die .h Datei).Code:int usonic();
Die neu erstellte Datei abspeichern mit richtiger Endung (wahrscheinlich .c oder .cc , so wie dein hauptprogramm), darauf achten dass es im richtigen Ordner landet.
Einbinden in dein Hauptprogramm:
Die Zeile muss irgendwo vor die int main()
Aufrufen z.B.Code:#include "DerDateiname.cc";
Der Abstandswert ist dann in der Variable abstand gespeichert.Code:int abstand=usonic();
(Falls der Rückgabewert -1 ist, reagiert das Ultraschallmodul nicht.)
War's so schwer?
MfG Bernhard
noch die Funktion usleep:
usleep(1) wartet 100uSekunden = 0,1ms = 0,0001 sCode://***********************************************//
// VOID USLEEP
// Wartet fuer 100*usec Mikro-Sekunden
// = msleep mit 10x hoeherer Aufloesung
// msleep(1) entspricht usleep(10)
//***********************************************//
void usleep(unsigned char usec)
{
for (int s=0; s<usec; s++) {
for (long int i=0; i<140; i++) {
asm volatile("nop");
asm volatile("nop");
}
}
}
Danke für deine Hilfe Bernhard!!!
Guck dir butte das an:
Ich bekomme folgende Fehlermeldungen:Code:/*****************************************************************************/
// Includes:
#include "RP6ControlLib.h" // The RP6 Control Library.
// Always needs to be included!
//#include "RP6I2CmasterTWI.h"
/*****************************************************************************/
/*****************************************************************************/
//***********************************************//
// VOID USLEEP
// Wartet fuer 100*usec Mikro-Sekunden
// = msleep mit 10x hoeherer Aufloesung
// msleep(1) entspricht usleep(10)
//***********************************************//
void usleep(unsigned char usec)
{
for (int s=0; s<usec; s++) {
for (long int i=0; i<140; i++) {
asm volatile("nop");
asm volatile("nop");
}
}
}
/*****************************************************************************/
/*****************************************************************************/
//Auszug aus ibex_header_v117.h
//(c) Bernhard Stiehle 2008-2010
//***********************************************//
// INT USONIC
// liefert den Abstand des Ultraschallsensors
// in Zentimetern. Es muss die Type SRF05 sein.
// Rueckgabewert -1 = Modul reagiert nicht/ außerhalb Bereich
//***********************************************//
int usonic()
{
int ustime=0; //Eine Variable bitte ... danke !
int failure=0; //Sicherheit
cbi(DDRA,2); //Anschluss als Eingang
cbi(PORTA,2); //Pull-ups sicherheitshalber ausschalten
sbi(DDRA,2); //Anschluss als Ausgang
cbi(PORTA,2); //Low-Pegel ausgeben
usleep(1); //Wartezeit
sbi(PORTA,2); //High-Impuls ausgeben (-> Sensor misst)
usleep(1); //Warten
cbi(PORTA,2); //Impuls Ende
cbi(DDRA,2); //Anschluss als Eingang
cbi(PORTA,2); //Pull-ups sicherheitshalber ausschalten
usleep(1); //warten
while( !(PINA & 4) ) //warten, bis der Sensor sein Signal
{ //zurueckgibt (warten solange low)
asm volatile("nop");
asm volatile("nop");
failure++; //Sicherheit: wenn kein Signal nach bestimmter Zeit kommt
if(failure>2500)
{return -1;} //dann -1 zurueck liefern (= kein Modul angeschlossen)
}
failure=0;
while(PINA & 4) //Signal hat begonnen (=high)
{
ustime++; //Dauer des Impulses messen
usleep(1); //Die Variable will eine Einheit (hier 0,1 ms)
failure++; //Sicherheit: wenn Signal nach bestimmter Zeit nicht endet
if(failure>5000)
{return -1;} //dann -1 zurueck liefern (= kein Modul angeschlossen)
}
mSleep(35); //Wartezeit (Echo soll verhallen, sonst Fehlmessung)
return int( float(ustime)*float(1.408) ); //Rueckgabewert in Zentimeter, bitte !
}
/*****************************************************************************/
// Main function - The program starts here:
int16_t main(void)
{
initRP6Control(); // Always call this first! The Processor will not work
// correctly otherwise.
// Play a sound to indicate that our program starts:
sound(100,40,64);
sound(170,40,0);
mSleep(400);
setLEDs(0b0000);
initLCD(); // Initialize the LC-Display (LCD)
// Always call this before using the LCD!
showScreenLCD(" SRF05 ", " Messung ");
mSleep(500);
//int abstand=usonic(); //FunktionsAufruf
// .... (abstand); Ausgabe auf dem LCD
return 0;
}
/*****************************************************************************/
Muss ich an "Makefile" was ändern?Code:
-------- begin --------
avr-gcc (GCC) 4.1.2 (WinAVR 20070525)
Copyright (C) 2006 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: srf05new.c
avr-gcc -c -mmcu=atmega32 -I. -gdwarf-2 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=srf05new.lst -I../../RP6lib -I../../RP6lib/RP6control -I../../RP6lib/RP6common -std=gnu99 -MD -MP -MF .dep/srf05new.o.d srf05new.c -o srf05new.o
srf05new.c:39: warning: function declaration isn't a prototype
srf05new.c: In function 'usonic':
srf05new.c:44: warning: implicit declaration of function 'cbi'
srf05new.c:47: warning: implicit declaration of function 'sbi'
srf05new.c:82: error: expected expression before 'int'
make.exe: *** [srf05new.o] Error 1
> Process Exit Code: 2
> Time Taken: 00:01
Also die Fehlermeldung Zeile 39 wegen Prototyp hättest du doch nochmaliges Lesen meines oberen Posts garantiert rausgekriegt
Sollte an dieser Stelle eingefügt werdenZitat:
Zitat von BMS
cbi und sbi (clearbit/setbit) kennt dein compiler anscheinend noch nicht.Code:....
// INT USONIC
// liefert den Abstand des Ultraschallsensors
// in Zentimetern. Es muss die Type SRF05 sein.
// Rueckgabewert -1 = Modul reagiert nicht/ außerhalb Bereich
//***********************************************//
int usonic(); //DAS IST NEU: PROTOTYP !!!!!
int usonic()
{
int ustime=0; //Eine Variable bitte ... danke !
int failure=0; //Sicherheit
....
Quelle des folgenden codes: http://www.mikrocontroller.net/topic/24517
sollte auch noch rein (z.b. vor der usleep-funktion)Code:#define sbi(ADDRESS,BIT) ((ADDRESS) |= (1<<(BIT)))
#define cbi(ADDRESS,BIT) ((ADDRESS) &= ~(1<<(BIT)))
Fehler in Zeile 82 ist mir noch unklar.
[/code]
Hallo Bernhard,
Das hatte ich gestern versucht, aber es gab eine Fehlermeldung mehr. Drum habe ich es wieder rausgenommen.Zitat:
Also die Fehlermeldung Zeile 39 wegen Prototyp hättest du doch nochmaliges Lesen meines oberen Posts garantiert rausgekriegt
Jetzt habe ich die Fehlermeldung zwei mal "funktion declaration isn't a prototype"
Code:> "make.exe" all
-------- begin --------
avr-gcc (GCC) 4.1.2 (WinAVR 20070525)
Copyright (C) 2006 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: srf05new.c
avr-gcc -c -mmcu=atmega32 -I. -gdwarf-2 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=srf05new.lst -I../../RP6lib -I../../RP6lib/RP6control -I../../RP6lib/RP6common -std=gnu99 -MD -MP -MF .dep/srf05new.o.d srf05new.c -o srf05new.o
srf05new.c:42: warning: function declaration isn't a prototype
srf05new.c:45: warning: function declaration isn't a prototype
srf05new.c: In function 'usonic':
srf05new.c:88: error: expected expression before 'int'
make.exe: *** [srf05new.o] Error 1
> Process Exit Code: 2
> Time Taken: 00:02
Mach mal die usleep und usonic-Funktionen unter die main, Prototypen müssen aber trotzdem vor die main.
Wenn ich die "usleep" Funktion unter die main setze, kriege ich noch zwei Fehlermeldungen:
Welchen Compiler benutzt du? Ich benutze den "Programmer's Notepad"Code:> "make.exe" all
-------- begin --------
avr-gcc (GCC) 4.1.2 (WinAVR 20070525)
Copyright (C) 2006 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: srf05new.c
avr-gcc -c -mmcu=atmega32 -I. -gdwarf-2 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=srf05new.lst -I../../RP6lib -I../../RP6lib/RP6control -I../../RP6lib/RP6common -std=gnu99 -MD -MP -MF .dep/srf05new.o.d srf05new.c -o srf05new.o
srf05new.c:25: warning: function declaration isn't a prototype
srf05new.c:28: warning: function declaration isn't a prototype
srf05new.c: In function 'usonic':
srf05new.c:38: warning: implicit declaration of function 'usleep'
srf05new.c:71: error: expected expression before 'int'
srf05new.c: At top level:
srf05new.c:109: warning: conflicting types for 'usleep'
srf05new.c:38: warning: previous implicit declaration of 'usleep' was here
make.exe: *** [srf05new.o] Error 1
> Process Exit Code: 2
> Time Taken: 00:03
"Programmers Notepad" ist kein Compiler.
Deiner Fehlermeldung nach benutzt du den GCC 4.1.2 von einer uralten WinAVR-Version von 2007...
Gabs 2007 eben noch nicht.Zitat:
cbi und sbi (clearbit/setbit) kennt dein compiler anscheinend noch nicht.
Die aktuelle Version ist von Januar 2010. Damit sollten dann einige Probleme weg sein.
Das mit der Version hat nicht viel gebracht...
So sieht die Fehlerliste jetzt aus:
Code:-------- begin --------
avr-gcc (WinAVR 20100110) 4.3.3
Copyright (C) 2008 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: srf05new.c
avr-gcc -c -mmcu=atmega32 -I. -gdwarf-2 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=srf05new.lst -I../../RP6lib -I../../RP6lib/RP6control -I../../RP6lib/RP6common -std=gnu99 -MD -MP -MF .dep/srf05new.o.d srf05new.c -o srf05new.o
srf05new.c:25: warning: function declaration isn't a prototype
srf05new.c:28: warning: function declaration isn't a prototype
srf05new.c: In function 'usonic':
srf05new.c:38: warning: implicit declaration of function 'usleep'
srf05new.c:71: error: expected expression before 'int'
srf05new.c: At top level:
srf05new.c:108: warning: conflicting types for 'usleep'
srf05new.c:38: warning: previous implicit declaration of 'usleep' was here
make: *** [srf05new.o] Error 1
> Process Exit Code: 2
> Time Taken: 00:01