#include <stdio.h>
#include <stm32f4xx.h>
void show(void)
{
int a,b;
for(a=2000;a>0;a--)
for(b=1200;b>0;b--);
}
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//使能GPIOF组引脚的时钟
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
//使能GPIOE组引脚的时钟
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,ENABLE);
//配置引脚初始化参数
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_13 | GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_Init(GPIOE, &GPIO_InitStructure);
while(1)
{
//让F9输出低电频
GPIO_ResetBits(GPIOF,GPIO_Pin_9);
show();
//让F9输出高电频
GPIO_SetBits(GPIOF,GPIO_Pin_9);
//让F10输出低电频
GPIO_ResetBits(GPIOF,GPIO_Pin_10);
show();
//让F10输出高电频
GPIO_SetBits(GPIOF,GPIO_Pin_10);
//让F13输出低电频
GPIO_ResetBits(GPIOE,GPIO_Pin_13);
show();
//让F9输出高电频
GPIO_SetBits(GPIOE,GPIO_Pin_13);
//让F10输出低电频
GPIO_ResetBits(GPIOE,GPIO_Pin_14);
show();
//让F10输出高电频
GPIO_SetBits(GPIOE,GPIO_Pin_14);
}
}
这是最基础的GPIO应用(流水灯),初学者一定记住使用那组引脚必须使能该组引脚时钟,再今后的定时器,串口也是一样;