systick.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "stm32f10x.h"
  2. #include "usart.h"
  3. #include "systick.h"
  4. volatile uint32_t TickCounter = 0;
  5. /**************************************************************************
  6. * systick_init
  7. **************************************************************************/
  8. void SysTickInit(uint16_t ms, uint8_t priority)
  9. {
  10. RCC_ClocksTypeDef RCC_Clocks;
  11. RCC_GetClocksFreq(&RCC_Clocks);
  12. SysTick_Config(RCC_Clocks.SYSCLK_Frequency /(1000/ms));
  13. NVIC_SetPriority (SysTick_IRQn, priority);
  14. }
  15. /**************************************************************************
  16. * SysTick_Handler
  17. **************************************************************************/
  18. void SysTick_Handler(void)
  19. {
  20. TickCounter++;
  21. }
  22. ///************************************************
  23. //函数名称 : delay_ms
  24. //功 能 : 软件延时
  25. //参 数 : cnt 延迟时间
  26. //返 回 值 : 无
  27. //作 者 : sun
  28. //*************************************************/
  29. //void delay_ms(uint32_t cnt)
  30. //{
  31. // volatile uint32_t i = cnt * 4510;
  32. //
  33. // while(i--);
  34. //}
  35. ///************************************************
  36. //函数名称 : delay_us
  37. //功 能 : 软件延时
  38. //参 数 : cnt 延迟时间
  39. //返 回 值 : 无
  40. //作 者 : sun
  41. //*************************************************/
  42. //void delay_us(uint32_t cnt)
  43. //{
  44. // volatile uint32_t i = cnt * 4;
  45. //
  46. // while(i--);
  47. //}