Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.61 KB | None | 0 0
  1. /**
  2. ****************************************************************************
  3. * @file main.c
  4. * @author Ac6
  5. * @version V1.0
  6. * @date 01-December-2013
  7. * @brief Default main function.
  8. ****************************************************************************
  9. */
  10.  
  11.  
  12. #include "stm32f4xx.h"
  13. #include "stm32f4_discovery.h"
  14.  
  15. unsigned int i = 0;
  16. unsigned int j = 1;
  17. unsigned int k =0;
  18.  
  19. int main(void)
  20. {
  21. // ustawienie trybu pracy priorytetów przerwań
  22. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  23.  
  24. NVIC_InitTypeDef NVIC_InitStructure;
  25. // numer przerwania
  26. NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
  27. // priorytet główny
  28. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x10;
  29. // subpriorytet
  30. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
  31. // uruchom dany kanał
  32. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  33. // zapisz wypełnioną strukturę do rejestrów
  34. NVIC_Init(&NVIC_InitStructure);
  35.  
  36. NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
  37. // priorytet główny
  38. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
  39. // subpriorytet
  40. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
  41. // uruchom dany kanał
  42. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  43. // zapisz wypełnioną strukturę do rejestrów
  44. NVIC_Init(&NVIC_InitStructure);
  45.  
  46.  
  47. GPIO_InitTypeDef GPIO_InitStructure;
  48. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  49. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8;
  50. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  51. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  52. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  53. GPIO_Init(GPIOA, &GPIO_InitStructure);
  54.  
  55. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  56. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13;
  57. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  58. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  59. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  60. GPIO_Init(GPIOE, &GPIO_InitStructure);
  61.  
  62.  
  63. RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
  64. TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  65. /* Time base configuration */
  66. TIM_TimeBaseStructure.TIM_Period = 9999;
  67. TIM_TimeBaseStructure.TIM_Prescaler = 8399;
  68. TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  69. TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  70. TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
  71. TIM_Cmd(TIM3, ENABLE);
  72. // wyczyszczenie przerwania od timera 3 (wystąpiło przy konfiguracji timera)
  73. TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
  74. // zezwolenie na przerwania od przepełnienia dla timera 3
  75. TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
  76.  
  77.  
  78. RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
  79. /* Time base configuration */
  80. TIM_TimeBaseStructure.TIM_Period = 9999;
  81. TIM_TimeBaseStructure.TIM_Prescaler = 2099;
  82. TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  83. TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  84. TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
  85. TIM_Cmd(TIM4, ENABLE);
  86. // wyczyszczenie przerwania od timera 3 (wystąpiło przy konfiguracji timera)
  87. TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
  88. // zezwolenie na przerwania od przepełnienia dla timera 3
  89. TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
  90.  
  91. RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  92. /* Time base configuration */
  93. TIM_TimeBaseStructure.TIM_Period = 41999;
  94. TIM_TimeBaseStructure.TIM_Prescaler = 1999;
  95. TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  96. TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  97. TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
  98. TIM_Cmd(TIM2, ENABLE);
  99. // wyczyszczenie przerwania od timera 3 (wystąpiło przy konfiguracji timera)
  100. TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
  101. // zezwolenie na przerwania od przepełnienia dla timera 3
  102. TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
  103.  
  104.  
  105. GPIO_SetBits(GPIOA,GPIO_Pin_0);
  106. GPIO_SetBits(GPIOA,GPIO_Pin_7);
  107. for(;;)
  108. {
  109.  
  110. }
  111. }
  112.  
  113. void TIM3_IRQHandler(void)
  114. {
  115.  
  116. if(TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
  117. {
  118. switch(i)
  119. {
  120. case 0:
  121. {
  122. i++;
  123. GPIO_ResetBits(GPIOA,GPIO_Pin_1);
  124. GPIO_ResetBits(GPIOA,GPIO_Pin_2);
  125. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  126. GPIO_ResetBits(GPIOA,GPIO_Pin_4);
  127. GPIO_ResetBits(GPIOA,GPIO_Pin_5);
  128. GPIO_ResetBits(GPIOA,GPIO_Pin_6);
  129. GPIO_SetBits(GPIOA, GPIO_Pin_7);
  130. break;
  131. }
  132. case 1:
  133. {
  134. i++;
  135. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  136. GPIO_SetBits(GPIOA,GPIO_Pin_2);
  137. GPIO_SetBits(GPIOA,GPIO_Pin_3);
  138. GPIO_SetBits(GPIOA,GPIO_Pin_6);
  139. break;
  140. }
  141. case 2:
  142. {
  143. i++;
  144. GPIO_ResetBits(GPIOA,GPIO_Pin_1);
  145. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  146. GPIO_ResetBits(GPIOA,GPIO_Pin_6);
  147. GPIO_ResetBits(GPIOA,GPIO_Pin_7);
  148. GPIO_SetBits(GPIOA,GPIO_Pin_5);
  149. break;
  150. }
  151. case 3:
  152. {
  153. i++;
  154. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  155. GPIO_ResetBits(GPIOA,GPIO_Pin_5);
  156. break;
  157. }
  158. case 4:
  159. {
  160. i++;
  161. GPIO_SetBits(GPIOA,GPIO_Pin_3);
  162. GPIO_SetBits(GPIOA,GPIO_Pin_6);
  163. GPIO_ResetBits(GPIOA,GPIO_Pin_4);
  164. GPIO_ResetBits(GPIOA,GPIO_Pin_2);
  165. break;
  166. }
  167. case 5:
  168. {
  169. i++;
  170. GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  171. GPIO_ResetBits(GPIOA,GPIO_Pin_6);
  172. GPIO_SetBits(GPIOA,GPIO_Pin_4);
  173. break;
  174. }
  175. case 6:
  176. {
  177. i++;
  178. GPIO_ResetBits(GPIOA,GPIO_Pin_1);
  179. break;
  180. }
  181. case 7:
  182. {
  183. i++;
  184. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  185. GPIO_SetBits(GPIOA,GPIO_Pin_2);
  186. GPIO_SetBits(GPIOA,GPIO_Pin_7);
  187. GPIO_SetBits(GPIOA,GPIO_Pin_6);
  188. GPIO_ResetBits(GPIOA,GPIO_Pin_4);
  189. break;
  190. }
  191. case 8:
  192. {
  193. i++;
  194. GPIO_ResetBits(GPIOA,GPIO_Pin_1);
  195. GPIO_ResetBits(GPIOA,GPIO_Pin_2);
  196. GPIO_ResetBits(GPIOA,GPIO_Pin_7);
  197. GPIO_ResetBits(GPIOA,GPIO_Pin_6);
  198. break;
  199. }
  200. case 9:
  201. {
  202. i = 0;
  203. GPIO_SetBits(GPIOA,GPIO_Pin_1);
  204. break;
  205. }
  206. }
  207. // wyzerowanie flagi wyzwolonego przerwania
  208. TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
  209. }
  210. }
  211.  
  212. void TIM4_IRQHandler(void)
  213. {
  214. if(TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET)
  215. {
  216. switch(j)
  217. {
  218. case 1:
  219. {
  220. GPIO_ToggleBits(GPIOE,GPIO_Pin_13);
  221. j++;
  222. GPIO_ToggleBits(GPIOA,GPIO_Pin_0);
  223. break;
  224. }
  225. case 2:
  226. {
  227. GPIO_ToggleBits(GPIOA,GPIO_Pin_0);
  228. j++;
  229. GPIO_ToggleBits(GPIOE,GPIO_Pin_11);
  230. break;
  231. }
  232. case 3:
  233. {
  234. GPIO_ToggleBits(GPIOE,GPIO_Pin_11);
  235. j++;
  236. GPIO_ToggleBits(GPIOE,GPIO_Pin_12);
  237. break;
  238. }
  239. case 4:
  240. {
  241. GPIO_ToggleBits(GPIOE,GPIO_Pin_12);
  242. j =0;
  243. GPIO_ToggleBits(GPIOE,GPIO_Pin_13);
  244. break;
  245. }
  246. }
  247. TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
  248. }
  249.  
  250.  
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement