Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.61 KB | None | 0 0
  1. #include "stm32f4xx.h"
  2. #include "stm32f4xx_gpio.h"
  3. #include "stm32f4xx_rcc.h"
  4. #define LED1 GPIOD, GPIO_Pin_12
  5. #define LED2 GPIOD, GPIO_Pin_13
  6. #define LED3 GPIOD, GPIO_Pin_14
  7. #define LED4 GPIOD, GPIO_Pin_15
  8. #define button GPIOA, GPIO_Pin_0
  9.  
  10. int wcisniety;
  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;
  17.     GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
  18.     GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  19.     GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  20.     GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
  21.     GPIO_Init(GPIOD, &GPIO_InitStruct);
  22. }
  23. static void button_setup(void)
  24. {
  25.     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  26.     GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
  27.     GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
  28.     GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  29.     GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
  30.     GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN;
  31.     GPIO_Init(GPIOA, &GPIO_InitStruct);
  32. }
  33.  
  34. int main(void){
  35.     GPIO_setup();
  36.     button_setup();
  37.     GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 |GPIO_Pin_14 |GPIO_Pin_15 );
  38.  
  39.     while(1)
  40.     {
  41.             if(GPIO_ReadInputDataBit(button == 1))
  42.             {
  43.                 if (wcisniety == 0) wcisniety = 1;
  44.                 else wcisniety = 0;
  45.  
  46.                 while(GPIO_ReadInputDataBit(button == 1))
  47.                 {}
  48.             }
  49.  
  50.  
  51.             if (wcisniety == 0)
  52.             {
  53.                 GPIO_ResetBits(GPIOD,  GPIO_Pin_12 | GPIO_Pin_13 |GPIO_Pin_14 |GPIO_Pin_15 ); //LED off
  54.             }
  55.             else
  56.             {
  57.                 GPIO_SetBits(LED1);
  58.                 GPIO_SetBits(LED2);
  59.                 GPIO_SetBits(LED3);
  60.                 GPIO_SetBits(LED4);
  61.             }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement