Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #include "stm32f4xx.h"
  2. #include "stm32f4xx_gpio.h"
  3. #include "stm32f4xx_rcc.h"
  4.  
  5. #define LED1 GPIOD, GPIO_Pin_12
  6. #define LED2 GPIOD, GPIO_Pin_13
  7. #define LED3 GPIOD, GPIO_Pin_14
  8. #define LED4 GPIOD, GPIO_Pin_15
  9. #define button GPIOA, GPIO_Pin_0
  10.  
  11. GPIO_InitTypeDef GPIO_InitStruct;
  12.  
  13. static void GPIO_setup(void)
  14. {
  15. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  16. GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13 | GPIO_Pin_12; // we want to configure all LED GPIO pins
  17. GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; // we want the pins to be an output
  18. GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; // this sets the GPIO modules clock speed
  19. GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; // this sets the pin type to push / pull (as opposed to open drain)
  20. GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; // this sets the pullup / pulldown resistors to be inactive
  21. GPIO_Init(GPIOD, &GPIO_InitStruct);
  22. }
  23.  
  24. static void button_setup(void)
  25. {RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  26. GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0; // we want to configure PA0
  27. GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; // we want it to be an input
  28. GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;//this sets the GPIO modules clock speed
  29. GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; // this sets the pin type to push / pull (as opposed to open drain)
  30. GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN; // this enables the pulldown resistor --> we want to detect a high level
  31. GPIO_Init(GPIOA, &GPIO_InitStruct);
  32. }
  33.  
  34. void clearBits()
  35. {
  36. GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 |GPIO_Pin_14 |GPIO_Pin_15);
  37. }
  38.  
  39. void lightLed(int number)
  40. {
  41. clearBits();
  42. switch(number)
  43. {
  44. case 0:
  45. {
  46. clearBits();
  47. GPIO_SetBits(GPIOD, GPIO_Pin_12);
  48. }
  49.  
  50. case 1:
  51. {
  52. clearBits();
  53. GPIO_SetBits(GPIOD, GPIO_Pin_13);
  54. }
  55.  
  56. case 2:
  57. {
  58. clearBits();
  59. GPIO_SetBits(GPIOD, GPIO_Pin_14);
  60. }
  61.  
  62. case 3:
  63. {
  64. clearBits();
  65. GPIO_SetBits(GPIOD, GPIO_Pin_15);
  66. }
  67.  
  68. case 4:
  69. {
  70. }
  71. }
  72. }
  73.  
  74. void lock()
  75. {
  76. while(GPIO_ReadInputData(GPIO_Pin_0 == 1))
  77. {
  78. }
  79. }
  80.  
  81. void Delay(__IO uint32_t nCount)
  82. {
  83. while(nCount--)
  84. {
  85. }
  86. }
  87.  
  88. int main(void)
  89. {
  90. GPIO_setup();
  91. button_setup();
  92. GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 |GPIO_Pin_14 |GPIO_Pin_15 );
  93.  
  94. task_2();
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement