- #include "stm8l15x.h"
- static void CLK_Config(void);
- static void TIM2_Config(void);
- void delayms(unsigned int w);
- void delayms(unsigned int w)
- {
- unsigned int i,j;
- for(i=0;i<w;i++)
- for(j=0;j<1000;j++);
- }
- /* 函数功能 ------------------------------------------------------------------*/
- /*******************************************************************************
- * @函数名称 main
- * @函数说明 主函数
- * @输入参数 无
- * @返回参数 无
- *******************************************************************************/
- void main(void)
- {
- /* CLK configuration -------------------------------------------*/
- CLK_Config();
- /* TIM2 configuration -------------------------------------------*/
- TIM2_Config();
- GPIO_Init(GPIOC, GPIO_Pin_6, GPIO_Mode_Out_PP_High_Fast);
- /* --使能 interrupts ---*/
- enableInterrupts();
- while (1)
- {
- }
- }
- static void CLK_Config(void)
- {
- /* ------使能 TIM2 时钟外设单元------ */
- // CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, ENABLE);
- /* High speed internal clock prescaler */
- CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_2);
- /*Enables or disables the clock switch execution*/
- CLK_SYSCLKSourceSwitchCmd(ENABLE);
- /*Configures the system clock (SYSCLK)
- * Select HSI as system clock source
- */
- CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
- /*HSI used as system clock
- * Returns the clock source used as system clock
- */
- while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_HSI)
- {}
- /* Enable TIM1 CLK */
- CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, ENABLE);
- CLK_PeripheralClockConfig(CLK_Peripheral_TIM1, ENABLE);
- }
- /*******************************************************************************
- * @函数名称 TIM2_Config
- * @函数说明
- * @输入参数
- * @输出参数 无
- * @返回参数 无
- *******************************************************************************/
- static void TIM2_Config(void)
- {
- TIM2_ETRClockMode1Config(TIM2_ExtTRGPSC_DIV8,//不分频
- TIM2_ExtTRGPolarity_Inverted,//触发极性
- 0x00); //滤波 低功耗模式下滤波关掉
- /* Time Base configuration */
- TIM2_TimeBaseInit(128, TIM2_CounterMode_Up, 8191);
- /* --清除TIM2溢出更新标志位-- */
- TIM2_ClearFlag(TIM2_FLAG_Update);
- /* --使能TIM2溢出更新中断-- */
- TIM2_ITConfig(TIM2_IT_Update, ENABLE);
- /* TIM2 counter enable */
- TIM2_Cmd(ENABLE);
- }
- /******************* (C) COPYRIGHT 2012 STMicroelectronics *****END OF FILE****/
- INTERRUPT_HANDLER(TIM2_UPD_OVF_TRG_BRK_IRQHandler,19)
- {
- /* In order to detect unexpected events during development,
- it is recommended to set a breakpoint on the following instruction.
- */
- if(TIM2_GetITStatus(TIM2_IT_Update)==SET)
- {
- TIM2_ClearITPendingBit(TIM2_IT_Update);
- GPIO_ToggleBits(GPIOC, GPIO_Pin_6);
- }
- }
中断进不去,头大了
|