stm32_跑马灯程序

/*在led.h文件编写如下代码:*/
#ifndef _led_H_
#define _led_H_

#include "sys.h"

/*GPIO的绑定*/
#define led0 PFout(9) //DS0
#define led1 PFout(10) //DS1

/*初始化*/
void led_Init(void);

#endif


/*在led.c文件编写如下代码:*/
#include "led.h"

/*初始化*/
void led_Init(void){
	GPIO_InitTypeDef GPIO_InitStruct;
	
	//时钟使能
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
	
	//GPIOF9,F10初始化设置
	GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;//LED0和LED1对应的IO口
	
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;//普通输出模式
	
	GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;//推挽输出
	
	GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;//上拉
	
	GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;//100Mz
	
	GPIO_Init(GPIOF,&GPIO_InitStruct);//初始化GPIO

	//设置为高电平
	GPIO_SetBits(GPIOF,GPIO_Pin_9 | GPIO_Pin_10);//GPIOF9,F10设置高,灯灭
	
	
}
/*在 main 函数里面编写如下代码:*/
#include "led.h"
int main(void)
{ 
delay_init(168); //初始化延时函数
LED_Init(); //初始化 LED 端口
/**下面是通过直接操作库函数的方式实现 IO 控制**/
while(1)
{
GPIO_ResetBits(GPIOF,GPIO_Pin_9); //LED0 对应引脚 GPIOF.9 拉低,亮 等同 LED0=0;
GPIO_SetBits(GPIOF,GPIO_Pin_10); //LED1 对应引脚 GPIOF.10 拉高,灭 等同 LED1=1;
delay_ms(500); //延时 500ms
GPIO_SetBits(GPIOF,GPIO_Pin_9); //LED0对应引脚GPIOF.0拉高,灭 等同LED0=1;
GPIO_ResetBits(GPIOF,GPIO_Pin_10); //LED1 对应引脚 GPIOF.10 拉低,亮 等同 LED1=0;
delay_ms(500); //延时 500ms
} 
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值