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

Reference to variables set by interruption (CC-RL)

Last Updated:05/10/2017

Question:

I am using RL78 Compiler CC-RL. I use a normal function to reference variables whose values are set by an interrupt function, but the values are not reflected.

(Example)

int data;
void func(void)
{
  data = 0;
  while(data == 0);  /* After data is set to 1 by an interrupt function, exit the loop. */

Answer:

If the volatile qualifier is not added in the variable definition, a code on which the value is not reflected might be output depending on the optimization settings.
When the variable value changes due to interruption, add the volatile qualifier in the variable definition.

(Example)
volatile int data;

Suitable Products
e² studio
CS+ (formerly CubeSuite+)
C Compiler Package for RL78 Family
  • 本文是否實用?