Defining a variable fails

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Defining a variable fails

1,644件の閲覧回数
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 返答(返信)

614件の閲覧回数
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 件の賞賛
返信

614件の閲覧回数
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 件の賞賛
返信