main.c 933 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "stm32f10x.h"
  2. int main ()
  3. {
  4. GPIO_TypeDef * gpiob =GPIOB;
  5. GPIO_TypeDef * gpioa =GPIOA;
  6. GPIO_InitTypeDef gpio_init_struct;
  7. int keyinput;
  8. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  9. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  10. gpio_init_struct.GPIO_Mode = GPIO_Mode_Out_PP;
  11. gpio_init_struct.GPIO_Speed = GPIO_Speed_50MHz;
  12. gpio_init_struct.GPIO_Pin = GPIO_Pin_0;
  13. //gpio_type.CRL =
  14. GPIO_Init (gpiob,&gpio_init_struct);
  15. gpio_init_struct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  16. GPIO_Init (gpioa,&gpio_init_struct);
  17. keyinput = 0;
  18. while (1)
  19. {
  20. if (gpioa->IDR & (1<<0))
  21. {
  22. while(gpioa->IDR & (1<<0));
  23. if(keyinput)
  24. {
  25. GPIO_ResetBits(gpiob,GPIO_Pin_0);
  26. keyinput=0;
  27. }
  28. else
  29. {
  30. GPIO_SetBits(gpiob,GPIO_Pin_0);
  31. keyinput=1;
  32. }
  33. }
  34. }
  35. return 0;
  36. }