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?
Solved! Go to Solution.
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 '{'):
Then this should work.
Erich
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
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
Erich's solution will also work.
Bhavin.
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 '{'):
Then this should work.
Erich