功能:让GPIOF的6—9引脚所连接的LED发光
GPIO_InitTypeDef GPIO_InitStructure;//定义变量GPIO_InitStructure,类型是GPIO_InitTypeDef的结构体类型
void Delay(uint32_t _tDly)
{
uint32_t i;
for(i = 0 ; i < _tDly ; i++)
{
;
}
}
int main(void)
{
SystemInit();//系统初始化
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);//使能GPIOF端口的时钟,使用任何外设的必备工作
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;//选择引脚
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //速率
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出模式
GPIO_Init(GPIOF,&GPIO_InitStructure);
while (1)
{
GPIOF -> BSRR = (1 << 6) | (1 << 7) | (1 << 8) | (1 << 9);//BSRR上拉模式
Delay(10000);
GPIOF -> BRR = (1 << 6) | (1 << 7) | (1 << 8) | (1 << 9);//BSRR下拉模式
Delay(10000);
}
}
当GPIO的Mode设置设为输入时,就不必设置GPIO的速率了。。。
问题:如果当同时使用GPIOA,GPIOB时,引脚选择的时候应该怎么办。(再定义一个GPIO_InitTypeDef型的变量?)