跳至主要內容
Knowledgebase
Home
Renesas Electronics Taiwan - Knowledgebase

How to see the modification after rewriting value of a variable?

Latest Updated:05/18/2015

Question:

I am using the CC-RL compiler for RL78 devices. I have attempted to rewrite the value of a variable from an interrupt function but the variable does not reflect the change of value I’m trying to make.

Answer:

Add the volatile qualifier to the declaration of any external variable to which a normal function or interrupt function refers.

Example:

int data;
void func(int x)
{
	

data = x; /* <- After a value is assigned to the variable “data”, even though    the interrupt function appears to write a new value to the variable, its value may not reflect this change. This is because the compiler uses the value of the variable “data” that has been stored in a register in advance. */
	・・・ 	
	if(data == 0)
	{
		・・・
	} 	
} 		
volatile int data;

To prevent this problem, add the above declaration.

Suitable Products
e² studio
CS+ (formerly CubeSuite+)
C Compiler Package for RL78 Family