Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f4xx.h"
- //#include "stm32f4xx_nucleo.h"
- #include "system_stm32f4xx.h"
- #include "stm32f4xx_hal_gpio.h"
- #include "stm32f4xx_hal_rcc.h"
- #include <stdio.h>
- #include "stm32f4xx_hal.h"
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.Pin = GPIO_PIN_1|GPIO_PIN_0;
- GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
- GPIO_InitStructure.Pull = GPIO_NOPULL;
- GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
- GPIO_InitStructure.Alternate = GPIO_AF7_USART1;
- HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
- GPIO_InitStructure.Pin = GPIO_PIN_7;
- GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStructure.Pull = GPIO_NOPULL;
- GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
- GPIO_InitStructure.Alternate = GPIO_AF7_USART1;
- HAL_GPIO_Init(GPIOE, &GPIO_InitStructure);
- GPIO_InitStructure.Pin = GPIO_PIN_4;
- GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
- GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
- GPIO_InitStructure.Alternate = GPIO_AF7_USART1;
- GPIO_InitStructure.Pull = GPIO_PULLDOWN;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_InitStructure.Pin = GPIO_PIN_5 | GPIO_PIN_6;
- GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
- GPIO_InitStructure.Pull = GPIO_NOPULL;
- GPIO_InitStructure.Speed =GPIO_SPEED_MEDIUM;
- GPIO_InitStructure.Alternate = GPIO_AF7_USART2;
- HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
- GPIO_PinAFConfig(GPIOD, GPIO_PIN_SOURCE5, GPIO_AF_USART2);
- GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2);
- }
- void led (void)
- {
- GPIO_ReadInputDataBit(GPIOA, GPIO_PIN_4);
- }
- int main(void){
- GPIO_Configuration();
- while(1){
- if(GPIO_ReadInputDataBit(GPIOA, GPIO_PIN_4))
- HAL_GPIO_WritePin(GPIOG, GPIO_PIN_1, GPIO_PIN_RESET);
- if(GPIO_ReadInputDataBit(GPIOA, GPIO_PIN_4)!= SET)
- HAL_GPIO_WritePin(GPIOG, GPIO_PIN_1, GPIO_PIN_SET);
- if(GPIO_ReadInputDataBit(GPIOA, GPIO_PIN_4))
- {
- HAL_GPIO_WritePin(GPIOE, GPIO_PIN_7, GPIO_PIN_SET);
- }
- if(GPIO_ReadInputDataBit(GPIOA, GPIO_PIN_4)!= SET)
- HAL_GPIO_WritePin(GPIOE, GPIO_PIN_7, GPIO_PIN_RESET);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement