#include "stm32f10x_lib.h"
#include "stm32f10x.h"
GPIO_InitTypeDef GPIO_InitStructure; //定义GPIO宏操作结构体
void Delay(__IO uint32_t nCount)//__IO的宏定义volatile
{
for(; nCount != 0; nCount--);
}
/*初始化嵌入式Flash接口,初始化PLL使其达到系统可用频率*/
void RCC_Configuration(void)
{
/* Setup the microcontroller system. Initialize the Embedded Flash Interface,
initialize the PLL and update the SystemFrequency variable. */
SystemInit();
}
int main()
{
int i;
RCC_Configuration(); //初始化FLASH及其PLL,系统时钟配置
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOB,ENABLE); //外设时钟配置,开启GPIOC的时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//将PC6\7\9口配置为通用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //口线翻转速度为50MHz
GPIO_Init(GPIOC, &GPIO_InitStructure); //配置GPIOC口
while(1)
{
GPIO_SetBits(GPIOC, GPIO_Pin_6); //PC6口输出高电平
GPIO_SetBits(GPIOC, GPIO_Pin_7); //PC7口输出高电平 GPIO_SetBits(GPIOC, GPIO_Pin_9); //PC9口输出高电平
for(i=0;i<1000000;i++);
GPIO_ResetBits(GPIOC, GPIO_Pin_6);
GPIO_ResetBits(GPIOC, GPIO_Pin_7);
// GPIO_ResetBits(GPIOC, GPIO_Pin_9);
// Delay(0xAFFFF);
for(i=0;i<1000000;i++);
}
}
具体代码工程在我的资源里:免费提供 http://download.youkuaiyun.com/detail/yx_l128125/4494861
步骤一声明GPIO的结构:
GPIO_InitTypeDef GPIO_InitStructure;
步骤二为变量GPIO_InitStructure的成员赋值,如果只设置其中的一部分成