How to use a volatile variable in RL78 (for Delay function)

Hi all,

I'm trying to build a delay function using a Timer (don't want to use the for loop). To achieve that I'm using a variable (tried normal as well as volatile). But, unfortunately, due to high and fast data manipulation process, the compiler taking a copy variable (and doing the arithmetic process on copy variable), hence the original variable is not getting modified. The function which I'm using to generate the Delay is stated below.

/*A Global variable*/
uint32_t TimingDelay = 0;
#define _USE_BUZZER  P2_bit.no3

/*Delay function of 10ms. the total delay will be Delay = nTime * 10ms */
void FnDelay_10ms( volatile uint32_t nTime)
  TimingDelay = nTime;
  /*Hold the code untill the count value turned to 0*/

  while(TimingDelay != 0x00){ ; }

/*A function to check whether the delay function is being called or not!*/
void TimingDelay_Decrement(void)
  if (TimingDelay != 0x00)
   {  TimingDelay--; }

/*This function is INTTM00 interrupt service routine*/
static void __near r_tau0_channel0_interrupt(void)
 /*Periodically check, whether the delay function is being called or not*/

 /*Whenever the delay function is called, the variable TimingDelay will be non zero. hence,
   it will start decrementing the variable after every 10ms.*/


/*This function implements main function*/
void main (void)
  while (1U)
     _USE_BUZZER = 1 ;
     _USE_BUZZER = 0 ;


In the above code, even the variable TimingDelay is getting 0 in the function TimingDelay_Decrement(), but the while condition in while(TimingDelay != 0x00) is not getting terminated, therefore, the main code is getting stuck at this while condition. So, please help me with above issue.