/*****************主要的用戶自己編寫的文件*********************/
/**
*********************************************************************
* @file : main.c
* @author : xr
* @date : 2014年5月13日08:31:58
* @version : V1.0
* @brief : STM32庫函數實現流水燈 STM32F103VE T6 MCU
*********************************************************************
* @attention
* 實驗平臺 : 野火STM32-MINI開發板
* 系統時鐘 : 采用默認的72MHZ
* 硬件連接 : --------------------------
* | PB0 -- LED1 |
* | PC4 -- LED2 |
* | PC3 -- LED3 |
* --------------------------
* 庫版本 : ST官方3.5.0版本
*********************************************************************
*/
#include "stm32f10x.h" /* 上帝之手 STM32官方庫頭文件 */
#include "led.h"
static void Delay( __IO uint32_t counter );
/**
* @brief : 主函數
* @param : 無
* @retval : 無
*/
int main(void)
{
/* 初始化LED控制端口 */
Config_LED_GPIO();
while (1)
{
LED1( ON ); //LED1亮
Delay( 0x36EE80 ); //延時50ms, xms / 1000 * 72000000 ->HEX = 0x36EE80
LED1( OFF ); //LED1滅
Delay( 0x36EE80 );
LED2( ON );
Delay( 0x36EE80 );
LED2( OFF );
Delay( 0x36EE80 );
LED3( ON );
Delay( 0x36EE80 );
LED3( OFF );
Delay( 0x36EE80 );
}
}
/**
* @brief : 不精確延時
* @param : None
* @retval : None
*/
static void Delay( __IO uint32_t counter )
{
while ( counter-- );
}
/***********************END OF FILE*************************************************/
#ifndef _LED_H_
#define _LED_H_
#include "stm32f10x.h" //使用stm32庫
/**
* 控制LED小燈的亮滅
* 1 -- OFF
* 0 -- ON
*/
#define OFF 1
#define ON 0
/* 帶參宏 如C++中的內聯函數一樣 */
#define LED1(a) if (a) \
GPIO_SetBits(GPIOB, GPIO_Pin_0);\
else \
GPIO_ResetBits(GPIOB, GPIO_Pin_0)
#define LED2(a) if (a) \
GPIO_SetBits(GPIOC, GPIO_Pin_4);\
else \
GPIO_ResetBits(GPIOC, GPIO_Pin_4)
#define LED3(a) if (a) \
GPIO_SetBits(GPIOC, GPIO_Pin_3);\
else \
GPIO_ResetBits(GPIOC, GPIO_Pin_3)
void Config_LED_GPIO(void);
#endif //_LED_H_
/********************************************END OF FILE******/
/**
************************************************************
* @file : led.c
* @author : xr
* @date : 2014年5月13日08:53:07
* @version : V1.0
* @brief : led 應用函數庫
************************************************************
* @attention
* 實驗平臺 : 野火STM32-ISO-MIN開發板
* 硬件連接 : --------------------------
* | PB0 -- LED1 |
* | PC4 -- LED2 |
* | PC3 -- LED3 |
* --------------------------
* 庫版本 : ST官方3.5.0
************************************************************
*/
#include "led.h"
/**
* @brief : 配置LED用到的I/O口
* @param : None
* @retval : None
*/
void Config_LED_GPIO(void)
{
/* 定義一個GPIO_InitTypeDef類型的結構體 */
GPIO_InitTypeDef GPIO_InitStructure;
/* 開啟GPIOB的外設時鐘 */
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
/* 開啟GPIOC的外設時鐘 */
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE );
/* 開啟LED引腳的外設時鐘 */
// RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE );
/* 選擇GPIOB引腳 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
/* 設置引腳模式為通用強推挽輸出 */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
/* 配置GPIOB引腳的速率為50M */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
/* 調用STM32庫函數初始化GPIOB0 */
GPIO_Init( GPIOB, &GPIO_InitStructure );
/* 選擇GPIOC 3-4 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;
/* 調用庫函數初始化LED2 3的控制引腳 */
GPIO_Init( GPIOC, &GPIO_InitStructure ); //以上已經設置了50M速率,故這里無需再設置!
/* 關閉所有LED等 */
GPIO_SetBits( GPIOB, GPIO_Pin_0 );
GPIO_SetBits( GPIOC, GPIO_Pin_4 | GPIO_Pin_3 );
}
/******************************************END OF FILE***********/