在线时间0 小时
UID299578
ST金币0
蝴蝶豆0
注册时间2011-6-17
中级会员
- 最后登录
- 1970-1-1
|
a0a.1 0b0c
/**
******************************************************************************
* @file TIM4/TIM4_TimeBase/main.c
* @author MCD Application Team
* @version V1.5.0
* @date 13-May-2011
* @brief Main program body
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* © COPYRIGHT 2011 STMicroelectronics
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"
#include "stm8_eval.h"
#define TIM4_PERIOD 124
__IO uint32_t TimingDelay;
/* Private function prototypes -----------------------------------------------*/
static void CLK_Config(void);
static void TIM4_Config(void);
void Delay(__IO uint32_t nTime);
void TimingDelay_Decrement(void);
void main(void)
{
/* CLK configuration -------------------------------------------*/
CLK_Config();
/* Initialize Leds mounted on STM8L1526-EVAL board */
STM_EVAL_LEDInit(LED1);
STM_EVAL_LEDInit(LED2);
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
/* Turn on LED1 and LED3 */
STM_EVAL_LEDOn(LED1);
STM_EVAL_LEDOn(LED3);
/* TIM4 configuration -------------------------------------------*/
TIM4_Config();
while (1)
{
/* Toggle LED2 and LED4 */
STM_EVAL_LEDToggle(LED2);
STM_EVAL_LEDToggle(LED4);
/* Insert 50 ms delay */
Delay(50);
/* Toggle LED1 and LED3 */
STM_EVAL_LEDToggle(LED1);
STM_EVAL_LEDToggle(LED3);
/* Insert 100 ms delay */
Delay(100);
}
}
static void CLK_Config(void)
{
CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
CLK_SYSCLKSourceSwitchCmd(ENABLE);
CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE);
while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_HSE)
{}
CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE);
}
static void TIM4_Config(void)
{
/
/* Time base configuration */
TIM4_TimeBaseInit(TIM4_Prescaler_128, TIM4_PERIOD);
/* Clear TIM4 update flag */
TIM4_ClearFlag(TIM4_FLAG_Update);
/* Enable update interrupt */
TIM4_ITConfig(TIM4_IT_Update, ENABLE);
/* enable interrupts */
enableInterrupts();
/* Enable TIM4 */
TIM4_Cmd(ENABLE);
}
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while (TimingDelay != 0);
}
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
这个函数干什么用的 ? |
|