Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 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. // pod pin Pin_6 podpinamy jeden wyświetlacza np.1
  13. // pod piny Pin_7,Pin_8,Pin_9,Pin_10 podpinamy jeden segment segmenty następująco a-7, b-8,f-9,g-10
  14. // pod piny Pin_11,Pin_12,Pin_13,Pin_14 podpinamy przyciski
  15.  
  16. #include "stm32f4xx.h"
  17. #include "stm32f4_discovery.h"
  18.  
  19. int a=0;
  20. int b=0;
  21. int f=0;
  22. int g=0;
  23.  
  24. void TIM3_IRQHandler(void){
  25. if(TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET){
  26. // miejsce na kod wywolywany w momencie wystapienia przerwania
  27. if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_11) == 0){
  28. if(a==0) a=1;
  29. else a=0;
  30. for(int i=0;i<10000;i++);
  31. }
  32. if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_12) == 0){
  33. if(b==0) b=1;
  34. else b=0;
  35. for(int i=0;i<10000;i++);
  36. }
  37. if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_13) == 0){
  38. if(f==0) f=1;
  39. else f=0;
  40. for(int i=0;i<10000;i++);
  41. }
  42. if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_14) == 0){
  43. if(g==0) g=1;
  44. else g=0;
  45. for(int i=0;i<10000;i++);
  46. }
  47.  
  48.  
  49. if(a==1){
  50. GPIO_ToggleBits(GPIOE,GPIO_Pin_7 );
  51. }
  52. else if(b==1){
  53. GPIO_ToggleBits(GPIOE,GPIO_Pin_8);
  54. }
  55. else if(f==1){
  56. GPIO_ToggleBits(GPIOE,GPIO_Pin_9);
  57. }
  58. else if(g==1){
  59. GPIO_ToggleBits(GPIOE,GPIO_Pin_10);
  60. }
  61. // wyzerowanie flagi wyzwolonego przerwania
  62. TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
  63.  
  64. }
  65. }
  66.  
  67.  
  68. int main(void)
  69. {
  70.  
  71. //timer
  72. RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
  73.  
  74. TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  75. TIM_TimeBaseStructure.TIM_Period = 5249;
  76. TIM_TimeBaseStructure.TIM_Prescaler = 3999;
  77. TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  78. TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  79. TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
  80.  
  81. TIM_Cmd(TIM3, ENABLE);
  82.  
  83. //ustawienie trybu pracy priorytetów przerwan
  84. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  85.  
  86. NVIC_InitTypeDef NVIC_InitStructure;
  87. //numer przerwania
  88. NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
  89. //priorytet glowny
  90. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
  91. //subpriorytet
  92. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
  93. //uruchom dany kanal
  94. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  95. //zapisz wypelniona strukture do rejestrow
  96. NVIC_Init(&NVIC_InitStructure);
  97. // wyczyszczenie przerwania od timera 3 (wystapilo przy konfiguracji timera)
  98. TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
  99. // zezwolenie na przerwania od przepelnienia dla timera 3
  100. TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
  101.  
  102.  
  103. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  104.  
  105. GPIO_InitTypeDef GPIO_InitStructure;
  106. GPIO_InitStructure.GPIO_Pin =
  107. GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
  108. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  109. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  110. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  111. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
  112. GPIO_Init(GPIOE, &GPIO_InitStructure);
  113.  
  114. GPIO_InitTypeDef GPIO_buttonIn;
  115. GPIO_buttonIn.GPIO_Pin =
  116. GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14;
  117. GPIO_buttonIn.GPIO_Mode = GPIO_Mode_IN;
  118. GPIO_buttonIn.GPIO_OType = GPIO_OType_PP;
  119. GPIO_buttonIn.GPIO_Speed = GPIO_Speed_100MHz;
  120. GPIO_buttonIn.GPIO_PuPd = GPIO_PuPd_UP;
  121. GPIO_Init(GPIOE, &GPIO_buttonIn);
  122.  
  123.  
  124.  
  125. GPIO_SetBits(GPIOE,GPIO_Pin_6);
  126. GPIO_SetBits(GPIOE,GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10);
  127. for(;;){
  128.  
  129.  
  130.  
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement