?? bsp_led.c
字號(hào):
/*
*********************************************************************************************************
*
* 模塊名稱 : LED指示燈驅(qū)動(dòng)模塊
* 文件名稱 : bsp_led.c
* 版 本 : V2.0
* 說 明 : 驅(qū)動(dòng)LED指示燈
* 修改記錄 :
* 版本號(hào) 日期 作者 說明
* v0.1 2009-12-27 armfly 創(chuàng)建該文件,ST固件庫版本為V3.1.2
* v1.0 2011-01-11 armfly ST固件庫升級(jí)到V3.4.0版本。
* v2.0 2011-10-16 armfly ST固件庫升級(jí)到V3.5.0版本。
* Copyright (C), 2010-2011, 安富萊電子 www.armfly.com
*
*********************************************************************************************************
*/
#include "stm32f10x.h"
#include <stdio.h>
#include "bsp_led.h"
/*
安富萊STM32F103ZE-EK開發(fā)板LED指示燈口線分配:
LED1 : PF6 低電平點(diǎn)亮
LED2 : PF7 低電平點(diǎn)亮
LED3 : PF8 低電平點(diǎn)亮
LED4 : PF9 低電平點(diǎn)亮
*/
#define GPIO_PORT_LED1 GPIOF
#define GPIO_PORT_LED2 GPIOF
#define GPIO_PORT_LED3 GPIOF
#define GPIO_PORT_LED4 GPIOF
#define GPIO_PIN_LED1 GPIO_Pin_6
#define GPIO_PIN_LED2 GPIO_Pin_7
#define GPIO_PIN_LED3 GPIO_Pin_8
#define GPIO_PIN_LED4 GPIO_Pin_9
#define GPIO_CLK_LED1 RCC_APB2Periph_GPIOF
#define GPIO_CLK_LED2 RCC_APB2Periph_GPIOF
#define GPIO_CLK_LED3 RCC_APB2Periph_GPIOF
#define GPIO_CLK_LED4 RCC_APB2Periph_GPIOF
/*
*********************************************************************************************************
* 函 數(shù) 名: bsp_InitLed
* 功能說明: 初始化LED指示燈
* 形 參:無
* 返 回 值: 無
*********************************************************************************************************
*/
void bsp_InitLed(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
#if 1 /* 采用宏定義的方式初始化GPIO,以便于修改GPIO口線 */
/* 打開GPIOF的時(shí)鐘 */
RCC_APB2PeriphClockCmd(GPIO_CLK_LED1 | GPIO_CLK_LED2 | GPIO_CLK_LED3 | GPIO_CLK_LED4, ENABLE);
/* 配置所有的LED指示燈GPIO為推挽輸出模式 */
/* 由于將GPIO設(shè)置為輸出時(shí),GPIO輸出寄存器的值缺省是0,因此會(huì)驅(qū)動(dòng)LED點(diǎn)亮
這是我不希望的,因此在改變GPIO為輸出前,先修改輸出寄存器的值為1 */
GPIO_SetBits(GPIO_PORT_LED1, GPIO_PIN_LED1);
GPIO_SetBits(GPIO_PORT_LED2, GPIO_PIN_LED2);
GPIO_SetBits(GPIO_PORT_LED3, GPIO_PIN_LED3);
GPIO_SetBits(GPIO_PORT_LED4, GPIO_PIN_LED4);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED1;
GPIO_Init(GPIO_PORT_LED1, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED2;
GPIO_Init(GPIO_PORT_LED2, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED3;
GPIO_Init(GPIO_PORT_LED3, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED4;
GPIO_Init(GPIO_PORT_LED4, &GPIO_InitStructure);
#else
/* 打開GPIOF的時(shí)鐘 */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);
/* 配置所有的LED指示燈GPIO為推挽輸出模式 */
/* 由于將GPIO設(shè)置為輸出時(shí),GPIO輸出寄存器的值缺省是0,因此會(huì)驅(qū)動(dòng)LED點(diǎn)亮
這是我不希望的,因此在改變GPIO為輸出前,先修改輸出寄存器的值為1 */
GPIO_SetBits(GPIOF, GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF, &GPIO_InitStructure);
#endif
}
/*
*********************************************************************************************************
* 函 數(shù) 名: bsp_LedOn
* 功能說明: 點(diǎn)亮指定的LED指示燈。
* 形 參:_no : 指示燈序號(hào),范圍 1 - 4
* 返 回 值: 按鍵代碼
*********************************************************************************************************
*/
void bsp_LedOn(uint8_t _no)
{
_no--;
if (_no == 0)
{
GPIO_PORT_LED1->BRR = GPIO_PIN_LED1;
}
else if (_no == 1)
{
GPIO_PORT_LED2->BRR = GPIO_PIN_LED2;
}
else if (_no == 2)
{
GPIO_PORT_LED3->BRR = GPIO_PIN_LED3;
}
else if (_no == 3)
{
GPIO_PORT_LED4->BRR = GPIO_PIN_LED4;
}
}
/*
*********************************************************************************************************
* 函 數(shù) 名: bsp_LedOff
* 功能說明: 熄滅指定的LED指示燈。
* 形 參:_no : 指示燈序號(hào),范圍 1 - 4
* 返 回 值: 按鍵代碼
*********************************************************************************************************
*/
void bsp_LedOff(uint8_t _no)
{
_no--;
if (_no == 0)
{
GPIO_PORT_LED1->BSRR = GPIO_PIN_LED1;
}
else if (_no == 1)
{
GPIO_PORT_LED2->BSRR = GPIO_PIN_LED2;
}
else if (_no == 2)
{
GPIO_PORT_LED3->BSRR = GPIO_PIN_LED3;
}
else if (_no == 3)
{
GPIO_PORT_LED4->BSRR = GPIO_PIN_LED4;
}
}
/*
*********************************************************************************************************
* 函 數(shù) 名: bsp_LedToggle
* 功能說明: 翻轉(zhuǎn)指定的LED指示燈。
* 形 參:_no : 指示燈序號(hào),范圍 1 - 4
* 返 回 值: 按鍵代碼
*********************************************************************************************************
*/
void bsp_LedToggle(uint8_t _no)
{
_no--;
if (_no == 0)
{
GPIO_PORT_LED1->ODR ^= GPIO_PIN_LED1;
}
else if (_no == 1)
{
GPIO_PORT_LED2->ODR ^= GPIO_PIN_LED2;
}
else if (_no == 2)
{
GPIO_PORT_LED3->ODR ^= GPIO_PIN_LED3;
}
else if (_no == 3)
{
GPIO_PORT_LED4->ODR ^= GPIO_PIN_LED4;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -