| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
-
- #include "stm32f10x.h"
- int main ()
- {
- GPIO_TypeDef * gpiob =GPIOB;
- GPIO_TypeDef * gpioa =GPIOA;
- GPIO_InitTypeDef gpio_init_struct;
- int keyinput;
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
-
-
- gpio_init_struct.GPIO_Mode = GPIO_Mode_Out_PP;
- gpio_init_struct.GPIO_Speed = GPIO_Speed_50MHz;
- gpio_init_struct.GPIO_Pin = GPIO_Pin_0;
- //gpio_type.CRL =
- GPIO_Init (gpiob,&gpio_init_struct);
- gpio_init_struct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init (gpioa,&gpio_init_struct);
-
- keyinput = 0;
-
- while (1)
- {
-
-
- if (gpioa->IDR & (1<<0))
- {
- while(gpioa->IDR & (1<<0));
-
- if(keyinput)
- {
- GPIO_ResetBits(gpiob,GPIO_Pin_0);
- keyinput=0;
- }
- else
- {
- GPIO_SetBits(gpiob,GPIO_Pin_0);
- keyinput=1;
- }
-
- }
-
- }
-
-
-
-
-
- return 0;
- }
|