Guest User

Untitled

a guest
Apr 1st, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <stm32f10x.h>
  2. #include <stm32f10x_rcc.h>
  3. #include <stm32f10x_gpio.h>
  4.  
  5. static __IO uint32_t TimingDelay;
  6.  
  7. void Delay(uint32_t nTime)
  8. {
  9. TimingDelay = nTime;
  10. while(TimingDelay != 0);
  11. }
  12.  
  13. void SysTick_Handler(void)
  14. {
  15. if(TimingDelay != 0)
  16. TimingDelay--;
  17. }
  18.  
  19. int main(void)
  20. {
  21. GPIO_InitTypeDef GPIO_InitStructure;
  22.  
  23. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  24.  
  25. GPIO_StructInit(&GPIO_InitStructure);
  26. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  27. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  28. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  29. GPIO_Init(GPIOB, &GPIO_InitStructure);
  30.  
  31. if(SysTick_Config(SystemCoreClock / 1000))
  32. while(1);
  33.  
  34. while(1)
  35. {
  36. static int ledval = 0;
  37.  
  38. GPIO_WriteBit(GPIOB, GPIO_Pin_0, (ledval) ? Bit_SET : Bit_RESET);
  39. ledval = 1 - ledval;
  40.  
  41. Delay(250);
  42. }
  43.  
  44. return 0;
  45. }
  46.  
  47. #ifdef USE_FULL_ASSERT
  48. void assert_failed(uint8_t *file, uint32_t line)
  49. {
  50. while(1);
  51. }
  52. #endif
Advertisement
Add Comment
Please, Sign In to add comment