123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include "stm32f10x.h"
- #include "stm32f10x_rcc.h"
- #include "stm32f10x_gpio.h"
- void initAll()
- {
-
- GPIO_InitTypeDef port;
-
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
-
- GPIO_StructInit(&port);
-
-
- port.GPIO_Mode = GPIO_Mode_IPD;
- port.GPIO_Pin = GPIO_Pin_1;
- port.GPIO_Speed = GPIO_Speed_2MHz;
-
-
-
- GPIO_Init(GPIOA, &port);
-
- port.GPIO_Mode = GPIO_Mode_Out_PP;
- port.GPIO_Pin = GPIO_Pin_0;
- port.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_Init(GPIOA, &port);
- }
- int main()
- {
-
- uint8_t buttonState = 0;
- initAll();
- while(1)
- {
-
-
- buttonState = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1);
- if (buttonState == 1)
- {
- GPIO_SetBits(GPIOA, GPIO_Pin_0);
- }
- else
- {
- GPIO_ResetBits(GPIOA, GPIO_Pin_0);
- }
- }
- }
|