本帖最后由 绝影 于 2015-12-16 21:01 编辑
STM32F469I点灯实验
开发板上有四个LED灯,链接方式如下图,只要对应的端口输出低电平就会点亮。
LED灯初始化函数如下图:
void Led_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOG_CLK_ENABLE(); //使能GPIOG时钟
__HAL_RCC_GPIOD_CLK_ENABLE(); //使能GPIOG时钟
__HAL_RCC_GPIOK_CLK_ENABLE(); //使能GPIOK时钟
/*LED1模式配置*/
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOG,&GPIO_InitStruct);
/*LED2,3模式配置*/
GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5;
HAL_GPIO_Init(GPIOD,&GPIO_InitStruct);
/*LED4模式配置*/
GPIO_InitStruct.Pin = GPIO_PIN_3;
HAL_GPIO_Init(GPIOK,&GPIO_InitStruct);
}
main函数如下:
int main(void)
{
/* STM32F4xx HAL library initialization:
- Configure the Flash prefetch and Buffer caches
- Systick timer is configured by default as source of time base, but user
can eventually implement his proper time base source (a general purpose
timer for example or other time source), keeping in mind that Time base
duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
handled in milliseconds basis.
- Low Level Initialization
*/
HAL_Init();
/* Configure the system clock to 180 MHz */
SystemClock_Config();
/* Add your application code here
*/
Led_Init();
/* Infinite loop */
while (1)
{
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_6,GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOD,GPIO_PIN_4|GPIO_PIN_5,GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOK,GPIO_PIN_3,GPIO_PIN_SET);
HAL_Delay(300);
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_6,GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOD,GPIO_PIN_4|GPIO_PIN_5,GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOK,GPIO_PIN_3,GPIO_PIN_RESET);
HAL_Delay(300);
}
}
其余函数文件都没有修改,下载完程序之后,看到4个LED灯在闪烁;
|