学习stm32的第四天

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);

	}
	
	
}



 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值