*以下文章资源均来自互联网,文章内容仅供参考,如果侵犯了您的权益,请留言或通过邮箱与我联系。
The following article resources are all from the Internet, the content of the article is for reference only. If you violate your rights and interests, please leave a message or contact me through email.
E-mail:chaoliang.hou@cn-depulong.com
/***************************************************************************************************************
在我学习STM32的时候使用的是正点原子的开发板,所以里面的有些代码可能使用了例程中的代码,如果这里会涉及利益上的问题,请与我取得联系。
/**************************************************************************************************************
STM32的I/O口的初始化大概分为以下几个步骤:
1.设置I/O口的时钟,就是你要选择你要初始化哪个I/O口(PA、PB、PC…)
2.设置你要初始化哪个I/O口(PA1 、PA2…)
3.设置I/O口的输入输出模式(是输入?还是输出?或者具体到各种模式)
4.设置I/O口的速度
下面直接用代码来说明:
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOE, ENABLE); //使能PB,PE端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED0-->PB.5 端口配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); //根据设定参数初始化GPIOB.5
GPIO_SetBits(GPIOB,