STM32F4探索者LED灯闪烁 |
您所在的位置:网站首页 › led资源库 › STM32F4探索者LED灯闪烁 |
原理
2个读取输入电平函数: uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);//读取某个GPIO的输入电平 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);//读取某组GPIO的输入电平2个读取输出电平函数: uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);//读取某个GPIO的输出电平 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);//读取某组GPIO的输出电平4个设置输出电平函数: void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);//设置某个IO口输出为高电平 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);//设置某个IO口输出为低电平 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal); void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);初始化GPIO void LED_Init() { GPIO_InitTypeDef GPIO_InitStructure;//定义结构体 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);//设置时钟使能 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;//设置为9和10口 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_UP;//上拉 GPIO_Init(GPIOF, &GPIO_InitStructure);//初始化GPIOF这里用了结构体 GPIO_SetBits(GPIOF,GPIO_Pin_9 | GPIO_Pin_10);//设置GPIOF9和10为高电平 }注: 1.推挽输出: 可以输出强高低电平,连接数字器件 开漏输出: 只可以输出强低电平,高电平得靠外部电阻拉高。输出端相当于三极管的集电极. 要得到高电平状态需要上拉电阻才行. 适合于做电流型的驱动,其吸收电流的能力相对强(一般20ma以内) 2.时钟使能函数我们可以在stm32f4xx_rcc.c中使用搜索功能(Ctrl+F)可以找到 3.函数的参数我们可以使用go to definition of来快速查找 例 led.h #ifndef __LED__H #define __LED__H void LED_Init(); #endifled.c #include"LED.H" #include"sys.h" void LED_Init() { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; 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_UP; GPIO_Init(GPIOF, &GPIO_InitStructure); GPIO_SetBits(GPIOF,GPIO_Pin_9 | GPIO_Pin_10); }main.c #include "sys.h" #include "delay.h" #include "usart.h" #include "led.h" int main(void) { delay_init(168); LED_Init(); while(1) { GPIO_ResetBits(GPIOF,GPIO_Pin_9); GPIO_SetBits(GPIOF,GPIO_Pin_10); delay_ms(500); GPIO_SetBits(GPIOF,GPIO_Pin_9); GPIO_ResetBits(GPIOF,GPIO_Pin_10); delay_ms(500); } } |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |