正点原子的程序:
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(GPIOA, &GPIO_InitStructure);
改编的程序:
void gpio_init(GPIO_TypeDef* GPIOx,uint16_t pinx,GPIOMode_TypeDef modex,GPIOSpeed_TypeDef speed,uint32_t RCC_APB2x)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2x, ENABLE); //使能GPIOx端口时钟
GPIO_InitStructure.GPIO_Pin = pinx; //端口选择
GPIO_InitStructure.GPIO_Mode = modex; //模式
GPIO_InitStructure.GPIO_Speed = speed; //速率
GPIO_Init(GPIOx, &GPIO_InitStructure); //初始化
GPIO_SetBits(GPIOx,pinx); //输出高
}
gpio_init(GPIOA,GPIO_Pin_13|GPIO_Pin_15,GPIO_Mode_IPU,GPIO_Speed_2MHz,RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO);
gpio_init(GPIOA,GPIO_Pin_0,GPIO_Mode_IPD,GPIO_Speed_2MHz,RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO);
这两个程序应该是一样的吧?
为什么用gpio_init替代正点原子的程序GPIOA0就不好使呀?
|