Advertisement
Guest User

STM32F401RE

a guest
Apr 7th, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include "stm32f4xx.h"
  2. #include "stm32f4xx_nucleo.h"
  3. #include "system_stm32f4xx.h"
  4. #include "stm32f4xx_hal_gpio.h"
  5. #include "stm32f4xx_hal_rcc.h"
  6.  
  7. GPIO_InitTypeDef GPIO_InitStructure;
  8.  
  9. int main(void) {
  10.    
  11.     HAL_Init();
  12.        
  13.     __GPIOA_CLK_ENABLE();
  14.         GPIO_InitStructure.Pin   = GPIO_PIN_5;
  15.         GPIO_InitStructure.Mode  = GPIO_MODE_OUTPUT_PP;    
  16.         GPIO_InitStructure.Pull  = GPIO_PULLUP;
  17.         GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;  
  18.         HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);    
  19.    
  20.         __GPIOC_CLK_ENABLE();
  21.         GPIO_InitStructure.Pin   = GPIO_PIN_13;
  22.         GPIO_InitStructure.Mode  = GPIO_MODE_INPUT;
  23.         GPIO_InitStructure.Pull  = GPIO_PULLDOWN;
  24.         GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
  25.         HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
  26.    
  27.     while (1) {
  28.         if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)) {        
  29.             HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
  30.         } else {
  31.             HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement