看example,都是RCC_Configuration和NVIC_Configuration开始 我菜,看不懂这两个东东,跳过她 直接GPIO_Init,LED和Key还是一样的用。 =================================================================== int main(void) { #ifdef DEBUG debug(); #endif
gpio_init(); gpio_test();
/* Infinite loop */ while (1) { } }
#define iKey2() GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3) #define oLED1(onoff) GPIO_WriteBit(GPIOC, GPIO_Pin_7, onoff) #define oLED2(onoff) GPIO_WriteBit(GPIOC, GPIO_Pin_6, onoff)
void gpio_init() { GPIO_InitTypeDef ioInit;
ioInit.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; ioInit.GPIO_Speed = GPIO_Speed_2MHz; ioInit.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &ioInit); //初始化LED输出
ioInit.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4; ioInit.GPIO_Speed = GPIO_Speed_2MHz; ioInit.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOD, &ioInit); //初始化Key输入 }
void gpio_test() { while(1) { if(iKey2()) { oLED1(Bit_SET); oLED2(Bit_RESET); } else { oLED2(Bit_SET); oLED1(Bit_RESET); } } }
|