Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 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. #include <stdio.h>
  7. #include "stm32f4xx_hal.h"
  8. void GPIO_Configuration(void)
  9. {
  10. GPIO_InitTypeDef GPIO_InitStructure;
  11.  
  12. GPIO_InitStructure.Pin = GPIO_PIN_1|GPIO_PIN_0;
  13. GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
  14. GPIO_InitStructure.Pull = GPIO_NOPULL;
  15. GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
  16. GPIO_InitStructure.Alternate = GPIO_AF7_USART1;
  17. HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
  18.  
  19. GPIO_InitStructure.Pin = GPIO_PIN_7;
  20. GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
  21. GPIO_InitStructure.Pull = GPIO_NOPULL;
  22. GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
  23. GPIO_InitStructure.Alternate = GPIO_AF7_USART1;
  24. HAL_GPIO_Init(GPIOE, &GPIO_InitStructure);
  25.  
  26. GPIO_InitStructure.Pin = GPIO_PIN_4;
  27. GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
  28. GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
  29. GPIO_InitStructure.Alternate = GPIO_AF7_USART1;
  30. GPIO_InitStructure.Pull = GPIO_PULLDOWN;
  31. HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
  32.  
  33. GPIO_InitStructure.Pin = GPIO_PIN_5 | GPIO_PIN_6;
  34. GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
  35. GPIO_InitStructure.Pull = GPIO_NOPULL;
  36. GPIO_InitStructure.Speed =GPIO_SPEED_MEDIUM;
  37. GPIO_InitStructure.Alternate = GPIO_AF7_USART2;
  38. HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
  39. GPIO_PinAFConfig(GPIOD, GPIO_PIN_SOURCE5, GPIO_AF_USART2);
  40. GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2);
  41. }
  42. void led (void)
  43. {
  44.  
  45. GPIO_ReadInputDataBit(GPIOA, GPIO_PIN_4);
  46.  
  47.  
  48. }
  49.  
  50. int main(void){
  51. GPIO_Configuration();
  52. while(1){
  53. if(GPIO_ReadInputDataBit(GPIOA, GPIO_PIN_4))
  54.  
  55.  
  56. HAL_GPIO_WritePin(GPIOG, GPIO_PIN_1, GPIO_PIN_RESET);
  57. if(GPIO_ReadInputDataBit(GPIOA, GPIO_PIN_4)!= SET)
  58.  
  59.  
  60. HAL_GPIO_WritePin(GPIOG, GPIO_PIN_1, GPIO_PIN_SET);
  61. if(GPIO_ReadInputDataBit(GPIOA, GPIO_PIN_4))
  62. {
  63.  
  64. HAL_GPIO_WritePin(GPIOE, GPIO_PIN_7, GPIO_PIN_SET);
  65. }
  66. if(GPIO_ReadInputDataBit(GPIOA, GPIO_PIN_4)!= SET)
  67.  
  68. HAL_GPIO_WritePin(GPIOE, GPIO_PIN_7, GPIO_PIN_RESET);
  69.  
  70.  
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement