hi leute. kenn mich irgenwie nicht so recht aus mit der erstellung von hex-files. wollte einfach mal zum ausprobieren dieses c-programm mit mfile von winavr in ein makefile und dann mit programmers-notepad in ein hex-file umwandeln.könnt ihr mir bitte genau erklären wie ich dabei vorgehe? kann es sein dass winavr die includes gar nicht kennt? was muss ich dann machen?hier der quelltext: #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; void Start (); void GetResults (); int i, j, life, maxrand; char c; void Start () { i = 0; j = 0; life = 0; maxrand = 6; cout << "Select difficulty mode:\n"; // the user has to select a difficutly level cout << "1 : Easy (0-15)\n"; cout << "2 : Medium (0-30)\n"; cout << "3 : Difficult (0-50)\n"; cout << "or type another key to quit\n"; c = 30; cin >> c; // read the user's choice cout << "\n"; switch (c) { case '1' : maxrand = 15; // the random number will be between 0 and maxrand break; case '2' : maxrand = 30; break; case '3' : maxrand = 50; break; default : exit(0); break; } life = 5; // number of lifes of the player srand( (unsigned)time( NULL ) ); // init Rand() function j = rand() % maxrand; // j get a random value between 0 and maxrand GetResults(); } void GetResults () { if (life <= 0) // if player has no more life then he lose { cout << "You lose !\n\n"; Start(); } cout << "Type a number: \n"; cin >> i; // read user's number if ((i>maxrand) || (i<0)) // if the user number isn't correct, restart { cout << "Error : Number not between 0 and \n" << maxrand; GetResults(); } if (i == j) { cout << "YOU WIN !\n\n"; // the user found the secret number Start(); } else if (i>j) { cout << "Too BIG\n"; life = life - 1; // -1 to the user's "life" cout << "Number of remaining life: " << life << "\n\n"; GetResults(); } else if (i<j) { cout << "Too SMALL\n"; life = life - 1; cout << "Number of remaining life:\n" << life << "\n\n"; GetResults(); } } int main () { cout << "** Jackpot game **\n"; cout << "The goal of this game is to guess a number. You will be ask to type\n"; cout << "a number (you have 5 guess)\n"; cout << "Jackpot will then tell you if this number is too big of too small compared to the secret number to find\n\n"; Start(); return 0; }
> #include <iostream>
Da fehlt schonmal das ".h". Abgesehen davon ist iostream.h eine
C++-Bibliothek und keine C-Bibliothek...
jetzt hab ichs geändert und dann bringt er mir trozdem den fehler: > "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. make.exe: *** No rule to make target `main.elf', needed by `elf'. Stop. > Process Exit Code: 2 > Time Taken: 00:01
Da liegt wahrscheinlich das Problem: Marcel versucht wahrscheinlich ein C++ Programm mit dem GCC zu kompilieren.... dafür ist aber G++ zuständig. C++ hat auf dem AVR einige Einschränkungen und ist i.d.R. zu "schwergewichtig". Du (Marcel) solltest also nur C für AVRs einsetzen. Zudem dürfte dein Programm auch keine Ausgabe bringen, da der AVR-G++ keine Standardklassen mitbringt, also auch nicht die IO-Klassen. Mehr dazu: http://www.roboternetz.de/phpBB2/zeigebeitrag.php?t=32705 Gruß, SIGINT P.S.: @Johannes: Wie ich eben gelesen hab ist die include ohne ".h" sogar richtig, da C++ includes wohl immer ohne Endung angegeben werden.
Sigint 112 wrote: > P.S.: @Johannes: Wie ich eben gelesen hab ist die include ohne ".h" > sogar richtig, da C++ includes wohl immer ohne Endung angegeben werden. Oh, zu lange nix mehr mit C++ zu tun gehabt... Hatte mir den Rest auch grad nicht richtig angeschaut... das "using" lässt auch darauf schließen, dass es sich tatsächlich um ein C++-Programm handelt. Das ist auch offensichtlich kein µC-Programm, da die ganze Peripherie-Initialisierung fehlt.
ich glaub ich mach beim makefile immer was falsch. ich geb immer ein: mcu-type: atmega8 c/c++ soure file und prot: usb dann speichere ich im ordner wo das .c file liegt ab. muss ich sonst noch was einstellen?
Das ist kein C-Programm. Das kann ein C-Compiler nicht übersetzen. #include <iostream> Das ist ein C++-Header (ohne *.h) using namespace std; Das ist C++. void Start (); void GetResults (); Das sind C++-Prototypen (ohne Argumentenliste wären sie allenfalls K&R-konform, also pre-C89) cout << "Select difficulty mode:\n"; C kennt keine I/O-Streams und kennt kein entsprechende Überladen des Shift-Operators, auch sind cout/cin unbekannt.
@Rufus: Na, hoffentlich kapiert er es diesmal. Steht schließlich so oder so ähnlich alles oben schon mal...
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.