Problems using CodeWarrior

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problems using CodeWarrior

Jump to solution
903 Views
bastianschoettn
Contributor I

Hallo everyone,

I have some problems using CodeWarrior.

For all my projects i have used Atmel Technology and the Atmel Studio. But for the next Project I have to use the MC9S12C32 EVB.

I use CodeWarrior IDE version 5.9.0 Build 5294.

 

After a few test i had several problems, with this IDE...

Could find the reason why my function was not working. The compiler ignored my prototypes... Don't know why but reentering them helped.

 

Now there is the problem with the typedef enum.

//#include and #define //################################## prototype ######################### typedef enum {C=0, Cis=1, D=2, Es=3, E=4, F=5, Fis=6, G=7, Gis=8, A=9, Bs=10, B=11} TONE;  void myinit(void); void initTone(void); void playFrequency(unsigned int); void playTone(TONE);  // ################################## main ############################# void main(void) {     myinit();     initTone();     TONE mytone = A; //this does not work     while(1)     {         playTone(mytone);     } }   //re//r

It is not working in main.c or if i try to import the typedef enum from a headerfile. Is there a special position where it has to be placed? Can someone help me with that?

Labels (1)
0 Kudos
1 Solution
555 Views
BlackNight
NXP Employee
NXP Employee

Hi Bastian,

in C you cannot place variable anywhere inside the code (you can do this in C++).

Move the mytone variable definition to the start of a block (beginning with '{'):

  1. void main(void
  2. TONE mytone = A; //this will work 
    ...

Then this should work.

Erich

View solution in original post

0 Kudos
4 Replies
555 Views
bastianschoettn
Contributor I

Thanks my bad, placing the variable at the wrong place...

I created and tested my code in CodeBlocks, where it was absolutely fine. I am not used to C anymore so the gcc compiler did that job me.

Thanks for the help!

Bastian

0 Kudos
555 Views
bhavinparmar
Contributor II

Hello Bastian,

You can do like this

typedef enum {C=0, Cis=1, D=2, Es=3, E=4, F=5, Fis=6, G=7, Gis=8, A=9, Bs=10, B=11} TONE;

TONE mytone;

 

void myinit(void); 

void initTone(void); 

void playFrequency(unsigned int); 

void playTone(TONE); 

void MCU_init(void); /* Device initialization function declaration */

void main(void)

{

    MCU_init(); /* call Device Initialization */

    myinit(); 

    initTone(); 

    mytone = A; //this does not work 

    while(1) 

    { 

        playTone(mytone); 

    } 

}

Here you have to declare variable outside the function as you have taken it as globle variable

0 Kudos
555 Views
bhavinparmar
Contributor II

Erich's solution will also work.

Bhavin.

0 Kudos
556 Views
BlackNight
NXP Employee
NXP Employee

Hi Bastian,

in C you cannot place variable anywhere inside the code (you can do this in C++).

Move the mytone variable definition to the start of a block (beginning with '{'):

  1. void main(void
  2. TONE mytone = A; //this will work 
    ...

Then this should work.

Erich

0 Kudos