1,开始写第一个程序了,跑马灯--固件库,学习了程序编写流程,写好后,编译没问题,然后通过st-link烧入,but报错了,“invalid rom table”,后面设置了能烧入但是功能实现不了,前一天还有用。
2,“invalid rom table”这个错误搞定了,可能是之前下载错误,我是先修改了晶振频率。下面附原文链接:http://t.csdnimg.cn/be4q5 感谢!
3,总结一下学到的内容:
IO口输出低电平,LED亮;IO口输出高电平,LED灭。
GPIO输出方式:推挽输出(上拉);
流程:使能IO时钟--初始化IO口模式--初始化IO口;
头文件定义:#ifndef
#ifndef __LED__H //避免头文件内容重复定义,结尾用#endif
#define __LED__H
#endif
下面附带代码 led.h
#ifndef __LED__H //避免头文件内容重复定义,结尾用#endif
#define __LED__H
void LED_Init(void);
#endif
led.c
#include "led.h"
#include "stm32f4xx.h" // Device header右键选择引入
void LED_Init(void){
GPIO_InitTypeDef GPIO_InitStructuer; //定义结构体可以go to 去看
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
//通过右键assert_param()函数括号内跳转,根据开发板原理图知道是GPIOF口,然后后面的参数使能;
//f9
GPIO_InitStructuer.GPIO_Pin=GPIO_Pin_9; //选择端口9
GPIO_InitStructuer.GPIO_Mode=GPIO_Mode_OUT; //选择输出模式
GPIO_InitStructuer.GPIO_OType=GPIO_OType_PP; //推挽模式
GPIO_InitStructuer.GPIO_PuPd=GPIO_PuPd_UP; //上拉
GPIO_InitStructuer.GPIO_Speed=GPIO_Speed_50MHz; //选择50MHZ频率
GPIO_Init(GPIOF,&GPIO_InitStructuer);
//灯灭输出高电平
GPIO_SetBits(GPIOF,GPIO_Pin_9);
//f10
GPIO_InitStructuer.GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructuer.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStructuer.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructuer.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStructuer.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOF,&GPIO_InitStructuer);
//灯灭输出高电平
GPIO_SetBits(GPIOF,GPIO_Pin_10);
//f6
GPIO_InitStructuer.GPIO_Pin=GPIO_Pin_6;
GPIO_InitStructuer.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStructuer.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructuer.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStructuer.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOF,&GPIO_InitStructuer);
//灯灭输出高电平
GPIO_SetBits(GPIOF,GPIO_Pin_6);
}
main.c
#include "stm32f4xx.h"
#include "usart.h"
#include "delay.h"
#include "led.h"
//点亮led
int main(void){
delay_init(168);
LED_Init();
while(1){
GPIO_SetBits(GPIOF,GPIO_Pin_6);
GPIO_SetBits(GPIOF,GPIO_Pin_9);
GPIO_SetBits(GPIOF,GPIO_Pin_10);
delay_ms(500);
GPIO_ResetBits(GPIOF,GPIO_Pin_6);
GPIO_ResetBits(GPIOF,GPIO_Pin_9);
GPIO_ResetBits(GPIOF,GPIO_Pin_10);
delay_ms(500);
}
}