我这样写的代码,本想是让led交替闪烁的,可是什么效果都没有,麻烦大家看看哪里出问题了
[mw_shl_code=c,true]
/*main.c*/
#include "stm8l15x.h"
#include "stm8l15x_gpio.h"
#include "stm8l15x_tim1.h"
#include "stm8l15x_it.h"
#include <intrinsics.h>
/**
* 时钟的配置函数,16分频
*/
void CLK_Config(void)
{
CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_16); //16 分频
CLK_PeripheralClockConfig(CLK_Peripheral_TIM4,ENABLE); //外设时钟定时器4使能
}
void GPIO_Config(void)
{
GPIO_Init(GPIOC,GPIO_Pin_7,GPIO_Mode_Out_PP_High_Slow);
GPIO_Init(GPIOE,GPIO_Pin_7,GPIO_Mode_Out_PP_High_Slow);
}
void TIM1_Config(void)
{
TIM1_SetCounter(0);
//8分频,使用向上计数模式125次,使用晶振1M
TIM1_TimeBaseInit(8,TIM1_CounterMode_Up,124,0);
/*Enables TIM1 peripheral Preload register on ARR*/
TIM1_ARRPreloadConfig(ENABLE);
/*清中断*/
TIM1_ClearFlag(TIM1_FLAG_Update);
/*Enables the specified TIM1 interrupts*/
TIM1_ITConfig(TIM1_IT_Update,ENABLE);
/*打开总中断*/
__enable_interrupt();
/*Enables the TIM1 peripheral.*/
TIM1_Cmd(ENABLE);
}
void main(void)
{
CLK_Config();
GPIO_Config();
TIM1_Config();
// __enable_interrupt();
while(1)
{
}
}
/*stm8l15x_it.c*/
INTERRUPT_HANDLER(SWITCH_CSS_BREAK_DAC_IRQHandler,17)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
// while (1);
static u16 i,j;
i++;
if(i==1000)
{
i=0;
j++;
if(j%2==1)
{
LED3_H(); //PE7为高电平,黄灯亮
LED4_L(); //PC7为低电平
}
else if(j%2==0)
{
LED3_L();
LED4_H(); //PC7为高电平,蓝灯亮
}
if(j==60000) /*防止溢出*/
{
j=0;
}
}
// TIM1_ClearFlag(TIM1_FLAG_Update); /*Clear the TIM1' Pending flags*/
TIM1_ClearITPendingBit(TIM1_IT_Update); /*Clear the TIM1' Pending Bits*/
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>