1、led.c的具体的代码:
/*----------------------------------------------------------*/
#include "led.h"
/* -------------------------------------------------------------------------
文件名:led.c
描述 :根据硬件连接配置LED端口,打开对应的寄存器
---------------------------------------------------------------------------*/
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//打开PB口时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
//打开PE口时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
//PB5,PE5引脚设置
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
//端口速度
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//端口模式,此为输出推挽模式
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_Init(GPIOE,&GPIO_InitStructure);
}初始化:首先进行时钟的打开,引脚的设置,端口速度设置,端口模式的设置
2、led.h的头文件
#ifndef __LED_H #define __LED_H #include "stm32f10x.h" #define LED2_OFF GPIO_SetBits(GPIOE,GPIO_Pin_5) #define LED2_ON GPIO_ResetBits(GPIOE,GPIO_Pin_5) #define LED2_REV GPIO_WriteBit(GPIOE,GPIO_Pin_5,(BitAction)(1-(GPIO_ReadOutputDataBit(GPIOE,GPIO_Pin_5)))) #define LED3_OFF GPIO_SetBits(GPIOB,GPIO_Pin_5) #define LED3_ON GPIO_ResetBits(GPIOB,GPIO_Pin_5) #define LED3_REV GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1-(GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_5)))) void LED_Init(void); #endifled的开关,翻转
3、main.c函数代码
/*----------------------------------------------------------------------------------
文件名称:控制LED2,LED3闪烁
硬件平台:STM32F103 开发板
作者 :求是
固件库 :V3.5
-----------------------------------------------------------------------------------*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "led.h"
int main(void)
{
uint32_t i;
<span style="white-space:pre"> </span>LED_Init();
LED2_ON;
LED3_OFF;
for(i=0; i < 0xffffff; i++)
while (1)
{
for(i = 0; i < 0xfffff;i++);
LED2_REV;
LED3_REV;
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/u011046042/article/details/47708927