【发布时间】:2014-03-30 10:58:38
【问题描述】:
在我看来,我的定时器中断不能正常工作。问题是中断函数内的计数器只增加一次。这是我的主要和计时器设置代码。
#include <m8c.h>
#include "PSoCAPI.h"
#include <stdio.h>
#include <stdlib.h>
char theStr[] = "PSoC LCD";
static char tmp[3];
static int counter = 0;
void main(void){
LCD_Start();
LCD_Position(0,5);
LCD_PrString(theStr);
M8C_EnableGInt;
Timer8_EnableInt();
Timer8_Start();
while (1);
}
#pragma interrupt_handler myTimerInt
void myTimerInt(void){
counter ++;
LCD_Position(1,0);
itoa(tmp, counter, 10);
LCD_PrString(tmp);
}
【问题讨论】:
-
中断处理程序的特点是它们应该小而快,尤其是不会导致嵌套中断发生。
-
@JoachimPileborg - 是的,'LCD_Position' 听起来不像我会从中断处理程序中调用的东西。
-
确实,打印到 LCD 可能有点费时。定时器中断多久触发一次?如果定时器中断率大幅降低,代码是否开始工作?
-
问题已解决!谢谢你们的cmets。