Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include "stm32f4xx.h"
  2. #include "stm32f4xx_gpio.h"
  3. #define RCC_AHB1Periph_GPIOA ((uint32_t)0x00000001)
  4. #define RCC_AHB1Periph_GPIOB ((uint32_t)0x00000002)
  5. #define RCC_AHB1Periph_GPIOC ((uint32_t)0x00000004)
  6.  
  7. void GPIO_Config(void){
  8. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC, ENABLE);
  9.  
  10. GPIO_InitTypeDef gpio;
  11. GPIO_StructInit(&gpio);
  12. gpio.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3
  13. | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
  14. gpio.GPIO_Mode = GPIO_Mode_OUT;
  15. gpio.GPIO_OType = GPIO_OType_PP;
  16. gpio.GPIO_PuPd = GPIO_PuPd_UP;
  17. GPIO_Init(GPIOB, &gpio);
  18.  
  19. GPIO_StructInit(&gpio);
  20. gpio.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
  21. gpio.GPIO_Mode = GPIO_Mode_IN;
  22. gpio.GPIO_OType = GPIO_OType_PP;
  23. gpio.GPIO_PuPd = GPIO_PuPd_UP;
  24. GPIO_Init(GPIOC, &gpio);
  25. }
  26.  
  27. int main(void)
  28.  
  29. {
  30. void sleep(int i){
  31. while(i) i--;
  32. }
  33.  
  34.  
  35. double x=0;
  36. GPIO_Config();
  37. while(1){
  38. GPIO_SetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 );
  39.  
  40. if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_0)==0){
  41. x=2^0;
  42. }
  43. else if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_1)==0){
  44. x=2^1;
  45. }
  46. else if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_2)==0){
  47. x=2^2;
  48. }
  49. else if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_3)==0){
  50. x=2^3;
  51. }
  52.  
  53.  
  54. if (x<=4){
  55.  
  56. GPIO_ResetBits(GPIOB, GPIO_Pin_4 | GPIO_Pin_5| GPIO_Pin_6 );
  57.  
  58. }
  59. else
  60. {
  61. GPIO_ResetBits(GPIOB, GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6);
  62. }
  63.  
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement