Defining a variable fails

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

Defining a variable fails

1,411 Views
SimFr
Contributor I
Hello,

I use the CodeWarrior IDE 5.9.0.

In an application for the MPC5516, I define a variable outside of any function as follows:
static unsigned long intervalUL = 0x10;
Doing so, after flashing the application on the MPC5516, the value of intervalUL is 0xA5A5A5A5.

If I define the variable as
const unsigned long intervalUL = 0x10;
the value of intervalUL is always 0x200.

If I define the variable as
unsigned long intervalUL = 0x10;
the value of intervalUL is always 0xA5A5A5A5.

What do I do wrong? The question may not be the most complex one, but I really don´t know how to define the variable.

Thank you very much in advance.

Best regards

SimFr

Labels (1)
0 Kudos
2 Replies

381 Views
CrasyCat
Specialist III
Hello
 
If you define a variable as
  static unsigned long intervalUL = 0x10;
or
  unsigned long intervalUL = 0x10;
specifies the variable is modifiable, so it will be allocated in RAM.
 
Defining the variable as
  const unsigned long intervalUL = 0x10;
specifies the variable is a constant and it will be allocated in FLASH. 
 
A Flash programmer will not initialize the variable. Variables allocated in RAM will be initialized in the startup code.Their initial value will be copied from ROM to RAM at Startup.
 
In order to make sure your variable gets initialized at startup make sure you use the startup code delivered by CodeWarrior.
Also I would recommend you to create your project using the Wizard and using the Internal FLASH build target to create the executable.
 
CrasyCat
0 Kudos

381 Views
jreyes085
Contributor I
Hi! Where can i get some information about defining variables in C for the MCF51QE128? I want to start programming, but i haven't found information that makes easier this task.

Thank you! i'll wait for your answer!
0 Kudos