STM32F4跑马灯实验(原子)

来源:互联网 发布:物竞化学品数据库 编辑:程序博客网 时间:2024/05/22 01:32

第13讲

–来自正点原子视频

  • 硬件连接:LED分别接在PF9和PF10脚,且低电平点亮led;
  • 用到的库函数:

    1. 头文件
      源文件对应的都有头文件,需添加到工程;
    2. 源文件(lib目录)
      misc.c(一般我们都不会删掉这个头文件)
      stm32f4xx_rcc.c(所有的工程都会用到,涉及到时钟的使能)
      stm32f4xx_gpio.c
      stm32f4xx_usart.c(正点原子程序需要)
  • led跑马灯函数实现流程

    1. 使能IO口的时钟。(调用RCC_AB1PeriphClockCmd();
      不同的外设调用的时钟使能函数可能不一样;)
    2. 初始化IO口的模式;
    3. 操作IO口;

    main.c文件

/****************时间:2016年4月27日 21:50:29实现功能:实现LED闪烁目的:学会如何操作IO口****************/#include "stm32f4xx.h"#include "led.h"#include "delay.h"int main(void){    delay_init(168);    LED_Init();    while(1)    {        GPIO_SetBits(GPIOF,(GPIO_Pin_9 | GPIO_Pin_10) );        delay_ms(500);        GPIO_ResetBits(GPIOF,(GPIO_Pin_9 | GPIO_Pin_10) );        delay_ms(500);    }    return 0;}

led.c文件

#include "led.h"//需要#include "stm32f4xx.h" 这个定义,而sys,h里面包含了这个头文件#include "sys.h"void LED_Init(void){    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_PuPd = GPIO_PuPd_UP;    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;    GPIO_Init(GPIOF,&GPIO_InitStructure);    GPIO_SetBits(GPIOF,(GPIO_Pin_9 | GPIO_Pin_10) );}

led.h文件

#ifndef __LED_H#define __LED_Hvoid LED_Init(void);#endif
0 0
原创粉丝点击