新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > STM32F103V---固件库使用---GPIO

STM32F103V---固件库使用---GPIO

作者: 时间:2016-11-18 来源:网络 收藏
使用了下STM32F10X的固件库,练习了下最简单的端口应用,看来还是很方便的。

/******************** GPIO应用********************
stm32库文件应用---GPIO
芯片型号:STM32F103V
引脚: LED->GPIOC_Pin_6
编写日期:2012年3月20日
作者: 郑文
效果: LED一闪一闪
*/

本文引用地址:https://www.eepw.com.cn/article/201611/315998.htm

#include "stm32f10x_conf.h"
#include "stm32f10x.h"


GPIO_InitTypeDef GPIO_InitStructure; //声明一个结构体

void RCC_Configuration(void); //时钟配置
void delayms(unsigned int count);//延时程序

/////////主程序//////////////
int main(void)
{
RCC_Configuration(); //系统时钟配置

RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1 |RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
RCC_APB2Periph_GPIOE, ENABLE);//使能各部分时钟


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //引脚6选中
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //最高输出速率50M
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //复用推挽输出
GPIO_Init(GPIOC, &GPIO_InitStructure); //初始化配置GPIO_C

while (1)
{

GPIO_SetBits(GPIOC, GPIO_Pin_6);// LED1亮
delayms(1000);
GPIO_ResetBits(GPIOC, GPIO_Pin_6);//LED1灭
delayms(1000);

}

}

////////////子程序//////////////////


void RCC_Configuration(void)
{
/* Setup the microcontroller system. Initialize the Embedded Flash Interface,
initialize the PLL and update the SystemFrequency variable. */
SystemInit();
}

/*************延时程序***************/
void delayms(unsigned int count)
{
unsigned int i,j;
for(i=0;ifor(j=0;j<5000;j++);
}



评论


技术专区

关闭