frage zwecks hex-files

Gast #623084
Lesenswert?
• ▲
▼
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;
}
Gast #623095
Lesenswert?
• ▲
▼
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
#623100
Lesenswert?
• ▲
▼
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.
#623153
Lesenswert?
• ▲
▼
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.
Gast #623181
Lesenswert?
• ▲
▼
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?
Persönliche Seite #623450
Lesenswert?
• ▲
▼
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.

Antwort schreiben

Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt. Bitte hier nur auf die ursprüngliche Frage antworten, für neue Fragen einen neuen Beitrag erstellen.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.