Browse Source

Added Delay(ms).

Vladimir N. Shilov 1 year ago
parent
commit
fd726d313d
2 changed files with 20 additions and 0 deletions
  1. 1 0
      src/main.c
  2. 19 0
      src/stm8s_it.c

+ 1 - 0
src/main.c

@@ -22,6 +22,7 @@
 #include "board.h"
 #include "i2c.h"
 #include "led.h"
+#include "delay.h"
 
 /* Private define ------------------------------------------------------------*/
 #define TIM4_PERIOD  (uint8_t)124

+ 19 - 0
src/stm8s_it.c

@@ -30,6 +30,7 @@
 /* Includes ------------------------------------------------------------------*/
 #include "stm8s_it.h"
 #include "led.h"
+#include "delay.h"
 
 /** @addtogroup Template_Project
   * @{
@@ -42,6 +43,7 @@
 extern __IO uint16_t ConversionBuffer[64];
 extern __IO uint8_t BufferIndex;
 static uint8_t LedCnt = 0;
+static __IO uint16_t TimingDelay;
 
 /* Private function prototypes -----------------------------------------------*/
 /* Private functions ---------------------------------------------------------*/
@@ -514,6 +516,11 @@ INTERRUPT_HANDLER(TIM6_UPD_OVF_TRG_IRQHandler, 23)
       LedCnt = 0;
       led_OutputValue();
    }
+   
+   /* Decrements the TimingDelay variable */
+   if (TimingDelay > 0) {
+      TimingDelay --;
+   }
  }
 #endif /* (STM8S903) || (STM8AF622x)*/
 
@@ -533,5 +540,17 @@ INTERRUPT_HANDLER(EEPROM_EEC_IRQHandler, 24)
   * @}
   */
 
+/**
+  * @brief  Inserts a delay time.
+  * @param  nTime: specifies the delay time length, in milliseconds.
+  * @retval None
+  */
+void Delay(__IO uint16_t nTime)
+{
+  TimingDelay = nTime;
+  while (TimingDelay != 0) {
+      wfi();
+  }
+}
 
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/