Defining a variable fails

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

Defining a variable fails

1,498 次查看
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

标签 (1)
标记 (1)
0 项奖励
回复
2 回复数

468 次查看
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 项奖励
回复

468 次查看
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 项奖励
回复