Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f4xx.h"
- #include "stm32f4xx_gpio.h"
- #include "stm32f4xx_rcc.h"
- #define LED1 GPIOD, GPIO_Pin_12
- #define LED2 GPIOD, GPIO_Pin_13
- #define LED3 GPIOD, GPIO_Pin_14
- #define LED4 GPIOD, GPIO_Pin_15
- #define button GPIOA, GPIO_Pin_0
- int wcisniety;
- GPIO_InitTypeDef GPIO_InitStruct;
- static void GPIO_setup(void)
- {
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13 | GPIO_Pin_12;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOD, &GPIO_InitStruct);
- }
- static void button_setup(void)
- {
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN;
- GPIO_Init(GPIOA, &GPIO_InitStruct);
- }
- int main(void){
- GPIO_setup();
- button_setup();
- GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 |GPIO_Pin_14 |GPIO_Pin_15 );
- while(1)
- {
- if(GPIO_ReadInputDataBit(button == 1))
- {
- if (wcisniety == 0) wcisniety = 1;
- else wcisniety = 0;
- while(GPIO_ReadInputDataBit(button == 1))
- {}
- }
- if (wcisniety == 0)
- {
- GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 |GPIO_Pin_14 |GPIO_Pin_15 ); //LED off
- }
- else
- {
- GPIO_SetBits(LED1);
- GPIO_SetBits(LED2);
- GPIO_SetBits(LED3);
- GPIO_SetBits(LED4);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement