Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. #include "stm32f4xx.h"
  2. #include "stm32f4xx_gpio.h"
  3. #include "stm32f4xx_rcc.h"
  4.  
  5. void Delay(volatile uint32_t tick)
  6. {
  7. for(uint32_t i = 0; i < tick; i++);
  8. }
  9.  
  10. void Play( uint32_t herz, uint32_t time)
  11. {
  12. uint32_t k;
  13. k=1000000/herz;
  14. time=time*100;
  15. for(int i=0; i<time;i+=k*2)
  16. {
  17. GPIO_SetBits(GPIOD, GPIO_Pin_11);
  18. Delay(k);
  19. GPIO_ResetBits(GPIOD, GPIO_Pin_11);
  20. Delay(k);
  21. }
  22.  
  23. }
  24.  
  25. int main(void)
  26. {
  27. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  28. // RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  29. GPIO_InitTypeDef GPIO_InitStruct;
  30. GPIO_StructInit(&GPIO_InitStruct);
  31. GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15| GPIO_Pin_11;
  32. GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
  33. GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
  34. GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  35. GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
  36. GPIO_Init(GPIOD, &GPIO_InitStruct);
  37.  
  38. /*GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11;
  39. GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
  40. GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
  41. GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  42. GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
  43. GPIO_Init(GPIOB, &GPIO_InitStruct);*/
  44.  
  45.  
  46. while(1)
  47. {
  48.  
  49.  
  50.  
  51. Play(500,250);
  52. Play(550,250);
  53. Play(600,250);
  54. Play(650,250);
  55. Play(700,250);
  56. Play(750,250);
  57. Play(800,250);
  58. Play(850,250);
  59. Play(1000,1000);
  60. Play(970,1000);
  61. Play(940,1500);
  62. Play(910,250);
  63. Play(880,250);
  64. Play(820,1500);
  65. Play(790,500);
  66. Play(850,1500);
  67. Play(820,500);
  68. Play(720,1500);
  69. Play(30,0.2);
  70. Play(720,1000);
  71. Play(30,0.2);
  72. Play(720,1000);
  73. Play(30,0.2);
  74. Play(720,1000);
  75. Play(30,0.2);
  76. Play(720,250);
  77. Play(30,0.2);
  78. Play(720,250);
  79. Play(30,0.2);
  80. Play(720,250);
  81. Play(30,0.2);
  82. Play(720,250);
  83. Play(30,0.2);
  84. Play(720,250);
  85. Play(30,0.2);
  86. Play(720,250);
  87. Play(30,0.2);
  88. Play(720,250);
  89. Play(30,0.2);
  90. Play(720,250);
  91. Play(30,0.2);//ffff
  92. Play(750,250);
  93. Play(30,0.2);
  94. Play(750,250);
  95. Play(30,0.2);
  96. Play(750,250);
  97. Play(30,0.2);
  98. Play(750,250);
  99. Play(30,0.2);
  100. Play(780,250);
  101. Play(30,0.2);
  102. Play(780,250);
  103. Play(30,0.2);
  104. Play(780,250);
  105. Play(30,0.2);
  106. Play(780,250);
  107. Play(30,0.2);//fffff
  108. // Play(880,250);
  109. //Play(910,250);
  110. Play(830,250);
  111. Play(860,250);
  112. Play(780,250);
  113. Play(810,250);
  114. Play(730,250);
  115. Play(760,250);
  116. Play(680,250);
  117. Play(710,250);
  118. Play(630,250);
  119. Play(660,250);
  120. Play(580,250);
  121. Play(610,250);
  122. Play(530,250);
  123. //Delay(2000000);
  124.  
  125. /*for(int i=0;i<1000000;i++){
  126. GPIO_SetBits(GPIOD, GPIO_Pin_11);
  127. Delay(2000);
  128. GPIO_ResetBits(GPIOD, GPIO_Pin_11);
  129. Delay(2000);*/
  130.  
  131. /* for(int i=0;i<1000000;i++){
  132. GPIO_SetBits(GPIOD, GPIO_Pin_11);
  133. Delay(10000);
  134. GPIO_ResetBits(GPIOD, GPIO_Pin_11);
  135. Delay(10000);
  136. }
  137.  
  138. */
  139.  
  140.  
  141. /*GPIO_SetBits(GPIOD, GPIO_Pin_15);
  142. Delay(100000);
  143. GPIO_ResetBits(GPIOD, GPIO_Pin_15);
  144. Delay(100000);
  145.  
  146. GPIO_SetBits(GPIOB, GPIO_Pin_1);
  147. Delay(500000);
  148. GPIO_ResetBits(GPIOB, GPIO_Pin_1);
  149. Delay(100000);*/
  150.  
  151.  
  152.  
  153.  
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement