TIM2进入不了中断

2019-07-19 21:50发布

最近在学习STM8L152C6 遇到问题
void TIME2_Init(U8 psc,U16 arr)
{
CLK_PCKENR1 = 1<<1;//使能TIM2时钟
TIM2_PSCR = psc;
TIM2_ARRH = (arr&0XFF00)>>8;
TIM2_ARRL = arr&0XFF;;

TIM2_CR1 = 1<<7;//开启预装载
TIM2_IER = 1<<0;//开启更新中断
TIM2_SR1 &= 0<<0;//清除中断标志位
TIM2_CR1 = 1<<0;//开启TIM2
}

@far @interrupt void TIM2_IRQHandler(void)
{
FLAG=1;
TIM2_SR1 &= 0<<0;//清除中断标志位
return;
}

在stm8_interrupt_vector.c里面定义
extern void _stext();     /* startup routine */
extern @far @interrupt void TIM2_IRQHandler(void);

struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */
{0x82, NonHandledInterrupt}, /* trap  */
{0x82, NonHandledInterrupt}, /* irq0  */
{0x82, NonHandledInterrupt}, /* irq1  */
{0x82, NonHandledInterrupt}, /* irq2  */
{0x82, NonHandledInterrupt}, /* irq3  */
{0x82, NonHandledInterrupt}, /* irq4  */
{0x82, NonHandledInterrupt}, /* irq5  */
{0x82, NonHandledInterrupt}, /* irq6  */
{0x82, NonHandledInterrupt}, /* irq7  */
{0x82, NonHandledInterrupt}, /* irq8  */
{0x82, NonHandledInterrupt}, /* irq9  */
{0x82, NonHandledInterrupt}, /* irq10 */
{0x82, NonHandledInterrupt}, /* irq11 */
{0x82, NonHandledInterrupt}, /* irq12 */
{0x82, NonHandledInterrupt}, /* irq13 */
{0x82, NonHandledInterrupt}, /* irq14 */
{0x82, NonHandledInterrupt}, /* irq15 */
{0x82, NonHandledInterrupt}, /* irq16 */
{0x82, NonHandledInterrupt}, /* irq17 */
{0x82, NonHandledInterrupt}, /* irq18 */
{0x82, NonHandledInterrupt}, /* irq19 */
{0x82, TIM2_IRQHandler}, /* irq20 */
{0x82, NonHandledInterrupt}, /* irq21 */
{0x82, NonHandledInterrupt}, /* irq22 */
{0x82, NonHandledInterrupt}, /* irq23 */
{0x82, NonHandledInterrupt}, /* irq24 */
{0x82, NonHandledInterrupt}, /* irq25 */
{0x82, NonHandledInterrupt}, /* irq26 */
{0x82, NonHandledInterrupt}, /* irq27 */
{0x82, NonHandledInterrupt}, /* irq28 */
{0x82, NonHandledInterrupt}, /* irq29 */
};

main()
{
TIME2_Init(7,1999);
_asm("rim"); //开启全局中断
while (1)
{}
}

为什么中断老进不去呀?


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
5条回答
little
1楼-- · 2019-07-19 22:12
问题解决了,是因为中断函数放错位置了,应该放在irq19的位置
2012lc
2楼-- · 2019-07-19 23:57
楼主:
void TIME2_Init(U8 psc,U16 arr)函数里的 “CLK_PCKENR1 = 1<<1;//使能TIM2时钟”,
等效于“CLK_PCKENR1 = 0x02;”
这是使能的Timer3的时钟啊~
使能TIM2时钟应该写成:“CLK_PCKENR1 = 1<<0;”吧


little
3楼-- · 2019-07-20 04:47
 精彩回答 2  元偷偷看……
正点原子
4楼-- · 2019-07-20 10:34
 精彩回答 2  元偷偷看……
qrffrq
5楼-- · 2019-07-20 11:48
其实是能进去的吧,我之前用的时候那个ARRH  ARRL跟你的值一样的,后来把ARRH改成零就能很快观察到进去了,不知道原理……

一周热门 更多>