AnsweredAssumed Answered

Need help understanding a piece of example code.

Question asked by zimmerman.doug on Jul 21, 2015
I have a modified an example code from a STM8S300 to run on a STM8S105c6 Discovery, to output to a LCD.   OK, it almost works, it compiles (using IAR workbench), it links, it loads into the STM8sDiscovery, but it hangs, I debug, and know where it hangs.  I change the code to get past that point and it now looks like it should work (I haven't hard wired the display to the Discovery). 
My problem is that I can't make any sense out of the code that it hangs on. The complete code is shown below. Its in the delay.c function (not modified from your example)  the statement

while (TimingDelay !=0);

I replace that with:    if (TimingDelay <0)
                                { TimingDelay--; }

The code no longer hangs, but I don't know if I'm generating the same delay.
My question is what is that code doing?  I see no interrupts being called, like the comment section states.  
Thank You

Here is the full code.

/* Includes ------------------------------------------------------------------*/
#include "stm8s.h"
#include "delay.h"
/* Private defines -----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* Global variables*/
volatile u32 TimingDelay;
/**
  ******************************************************************************
  * @brief Delay before completing the action
  * @param[in] Delay value in milliseconds
  * None
  * @retval void None
  * @par Required preconditions:
  * None
  ******************************************************************************
  */
void Delay(u32 nTime)
{
  /* Wait delay elapsed by interrupt update of timingdelay variable*/
  TimingDelay = nTime;
  while (TimingDelay != 0);
}
/**
  ******************************************************************************
  * @brief Decrement initial value at each interrupt
  * @param[in]
  * None
  * @retval void None
  * @par Required preconditions:
  * None
  ******************************************************************************
  */
void TimingDelay_Decrement(void)
{
  if (TimingDelay != 0x00)
  {
    TimingDelay--;
  }
}

Outcomes