Problems using CodeWarrior

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Problems using CodeWarrior

跳至解决方案
1,731 次查看
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?

标签 (1)
0 项奖励
回复
1 解答
1,383 次查看
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 项奖励
回复
4 回复数
1,383 次查看
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 项奖励
回复
1,383 次查看
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 项奖励
回复
1,383 次查看
bhavinparmar
Contributor II

Erich's solution will also work.

Bhavin.

0 项奖励
回复
1,384 次查看
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 项奖励
回复