/*MAIN.C*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "misc.h"
/* Private function prototypes -----------------------------*/
void RCC_Configuration(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void TIM3_Configuration(void);
/* Private functions ------------------------------------------*/
/**
* @brief Main program
* @param None
* @retval : None
*/
int main(void)
{
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
TIM3_Configuration();
while (1) {
;
}
}
/**
* @brief Configures TIM3
* @param None
* @retval : None
*/
void TIM3_Configuration(void)
{
/*每1秒发生一次更新事件(进入中断服务程序)。RCC_Configuration()的SystemInit()的RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2表明TIM3CLK为72MHz。因此,每次进入中断服务程序间隔时间为((1+TIM_Prescaler )/72M)*(1+TIM_Period )=((1+7199)/72M)*(1+9999)=1秒 */
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 7199;
TIM_TimeBaseStructure.TIM_Prescaler = 9999;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);/*此函数的语句"TIMx->EGR = TIM_PSCReloadMode_Immediate;"以软件方式产生更新事件(注:当发生一个更新事件时,所有的寄存器都被更新,硬件同时(依据URS位)设置更新标志位(TIMx_SR寄存器中的UIF位)。)。*/
TIM_ClearFlag(TIM3, TIM_FLAG_Update);/*清除更新标志位*/
TIM_ARRPreloadConfig(TIM3, DISABLE);/*预装载寄存器的内容被立即传送到影子寄存器 */
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM3, ENABLE);
}
}
/**
* @brief Configures NVIC.
* @param None
* @retval : None
*/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the TIM3 gloabal Interrupt*/
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**
* @brief Configure the TIM3 Ouput Channels.
* @param None
* @retval : None
*/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/*注:不用为实现通用定时器的基本定时器功能配置Pin*/
}
/*stm32f10x_it.c*/
/* Includes -------------------------------------------------*/
#include "stm32f10x_it.h"
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) {
/* Clear TIM3 update interrupt */
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
GPIO_WriteBit(GPIOC, GPIO_Pin_7, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_7)));
}
}
/*注:stm32f10x_stdperiph_lib_v3.0.0 编译器:MDK3.24A*/
/*软件仿真:首次进入中断Sec为1.00016507,第二次进入中断Sec为2.00016507,因此2.00016507-1.00016507=1*/
/*
*/
用户340315 2011-6-8 10:01
用户1584993 2009-7-7 10:03
tengjingshu_112148725 2009-7-6 23:42
用户193558 2009-6-30 16:14
用户193558 2009-6-30 16:12
tengjingshu_112148725 2009-6-18 14:15