【STM32F407开发板试用体验】+7跑马灯程序
流水灯程序设计分析一、硬件设计:
图中可以看出LED0对应于STM32的GPIOF的9 PIN;LED1对应于GPIOF的10 PIN上。同时,管脚在LED端被拉高到3.3V。二、设计分析:1、图中GPIOF的9和10管脚被定义LED; 2、由于对LED操作需要单片机可以输出高低电平来控制LED灯的点亮和熄灭,故需定义LED灯管脚为推免输出模式。注意:(推挽输出:可以输出强高低电平,连接数字器件。) 3、本次用到的寄存器:端口模式寄存器(GPIOx_MODER)端口输出类型寄存器(GPIOx_OTYPER)端口输出速度寄存器(GPIOx_OSPEEDR)端口上拉下拉寄存器(GPIOx_PUPDR)端口输入数据寄存器(GPIOx_IDR)端口输出数据寄存器(GPIOx_ODR)端口置位/复位寄存器(GPIOx_BSRR)端口配置锁存寄存器(GPIOx_LCKR) 4、使用到的额外函数体: 文件:stm32F4xx_gpio.h和stm32f4xx_gpio.c; 使用的重要结构体: 1)typedef struct{ uint32_t GPIO_Pin; //初始化IO口 GPIOMode_Typedef GPIO_Mode; GPIOSpeed_TypeDef GPIO_Speed; GPIOOType_TypeDef GPIO_Otype; //输出类型 GPIOPuPd_TypeDef GPIO_PuPd;}GPIO_InitTypeDef;2)typedef enum{GPIO_Mode_IN = 0x00,GPIO_Mode_OUT = 0x01,GPIO_Mode_AF = 0x02,GPIO_Mode_AN = 0x03}GPIOMode_TypeDef; 3) typedef enum{GPIO_OType_PP = 0x00,GPIO_OType_OD = 0x01}GPIOOType_TypeDef; 4) typedef enum{ GPIO_Low_Speed = 0x00, /*!< Low speed */ GPIO_Medium_Speed = 0x01, /*!< Medium speed */ GPIO_Fast_Speed = 0x02, /*!< Fast speed */ GPIO_High_Speed = 0x03 /*!< High speed */}GPIOSpeed_TypeDef; 5) typedef enum{ GPIO_PuPd_NOPULL = 0x00, GPIO_PuPd_UP = 0x01, GPIO_PuPd_DOWN = 0x02}GPIOPuPd_TypeDef;5、使用到的函数:GPIO_Init(GPIOF,&GPIO_InitStructure);GPIO_Init(GPIO_TypeDef*GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);GPIO_SetBits(GPIOF,GPIO_Pin_9|GPIO_Pin_10);GPIO_ResetBits(GPIOF,GPIO_Pin_9|GPIO_Pin_10);三、建立第一个跑马灯程序工程样板:
113399四、程序设计:
#include "stm32f4xx.h"
#include "usart.h"
#include "delay.h"
#include "sys.h"
void delay(uint32_t count);
void delay(uint32_t count)
{
while(count --);
}
int main()
{
//delay_init(168);
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE); //Init RCC clock; LED for GPIOF
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //Push_Pull(PP),
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //yuanlitu
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF,&GPIO_InitStructure);
GPIO_SetBits(GPIOF,GPIO_Pin_9);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //Push_Pull(PP),
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //yuanlitu
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF,&GPIO_InitStructure);
GPIO_SetBits(GPIOF,GPIO_Pin_10);
while(1)
{
GPIO_SetBits(GPIOF,GPIO_Pin_9);
GPIO_SetBits(GPIOF,GPIO_Pin_10);
delay(0x7fffff);
GPIO_ResetBits(GPIOF,GPIO_Pin_9);
GPIO_ResetBits(GPIOF,GPIO_Pin_10);
delay(0x7fffff);
}
}
但是下载进开发板后怎么就不能显示呢???
暂时找不到问题!
流水灯程序设计分析一、硬件设计:
图中可以看出LED0对应于STM32的GPIOF的9 PIN;LED1对应于GPIOF的10 PIN上。同时,管脚在LED端被拉高到3.3V。二、设计分析:1、图中GPIOF的9和10管脚被定义LED; 2、由于对LED操作需要单片机可以输出高低电平来控制LED灯的点亮和熄灭,故需定义LED灯管脚为推免输出模式。注意:(推挽输出:可以输出强高低电平,连接数字器件。) 3、本次用到的寄存器:端口模式寄存器(GPIOx_MODER)端口输出类型寄存器(GPIOx_OTYPER)端口输出速度寄存器(GPIOx_OSPEEDR)端口上拉下拉寄存器(GPIOx_PUPDR)端口输入数据寄存器(GPIOx_IDR)端口输出数据寄存器(GPIOx_ODR)端口置位/复位寄存器(GPIOx_BSRR)端口配置锁存寄存器(GPIOx_LCKR) 4、使用到的额外函数体: 文件:stm32F4xx_gpio.h和stm32f4xx_gpio.c; 使用的重要结构体: 1)typedef struct{ uint32_t GPIO_Pin; //初始化IO口 GPIOMode_Typedef GPIO_Mode; GPIOSpeed_TypeDef GPIO_Speed; GPIOOType_TypeDef GPIO_Otype; //输出类型 GPIOPuPd_TypeDef GPIO_PuPd;}GPIO_InitTypeDef;2)typedef enum{GPIO_Mode_IN = 0x00,GPIO_Mode_OUT = 0x01,GPIO_Mode_AF = 0x02,GPIO_Mode_AN = 0x03}GPIOMode_TypeDef; 3) typedef enum{GPIO_OType_PP = 0x00,GPIO_OType_OD = 0x01}GPIOOType_TypeDef; 4) typedef enum{ GPIO_Low_Speed = 0x00, /*!< Low speed */ GPIO_Medium_Speed = 0x01, /*!< Medium speed */ GPIO_Fast_Speed = 0x02, /*!< Fast speed */ GPIO_High_Speed = 0x03 /*!< High speed */}GPIOSpeed_TypeDef; 5) typedef enum{ GPIO_PuPd_NOPULL = 0x00, GPIO_PuPd_UP = 0x01, GPIO_PuPd_DOWN = 0x02}GPIOPuPd_TypeDef;5、使用到的函数:GPIO_Init(GPIOF,&GPIO_InitStructure);GPIO_Init(GPIO_TypeDef*GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);GPIO_SetBits(GPIOF,GPIO_Pin_9|GPIO_Pin_10);GPIO_ResetBits(GPIOF,GPIO_Pin_9|GPIO_Pin_10);三、建立第一个跑马灯程序工程样板:
113399四、程序设计:
#include "stm32f4xx.h"
#include "usart.h"
#include "delay.h"
#include "sys.h"
void delay(uint32_t count);
void delay(uint32_t count)
{
while(count --);
}
int main()
{
//delay_init(168);
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE); //Init RCC clock; LED for GPIOF
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //Push_Pull(PP),
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //yuanlitu
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF,&GPIO_InitStructure);
GPIO_SetBits(GPIOF,GPIO_Pin_9);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //Push_Pull(PP),
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //yuanlitu
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF,&GPIO_InitStructure);
GPIO_SetBits(GPIOF,GPIO_Pin_10);
while(1)
{
GPIO_SetBits(GPIOF,GPIO_Pin_9);
GPIO_SetBits(GPIOF,GPIO_Pin_10);
delay(0x7fffff);
GPIO_ResetBits(GPIOF,GPIO_Pin_9);
GPIO_ResetBits(GPIOF,GPIO_Pin_10);
delay(0x7fffff);
}
}
但是下载进开发板后怎么就不能显示呢???
暂时找不到问题!