智能车制作
标题:
编写xs128测试硬件的时候,采用两个中断出现错误
[打印本页]
作者:
wjfuture
时间:
2014-7-17 19:36
标题:
编写xs128测试硬件的时候,采用两个中断出现错误
两个中断只有中断向量号是11的那个中断可以正常工作,另一个没有工作。新手,求大神帮助!谢谢了!
代码如下:
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include"WordLib.h"
#include "Nokia5110ForXS128.h"
unsigned int Input_Num,i,state,length2,result;
unsigned int length[6];
//宏定义布尔类型
#define BOOL int
#define TRUE 1
#define FALSE 0
BOOL flag = FALSE;//定义一个布尔变量
//bit k;
//--------------------通道 2 3 输入捕捉初始化-------------------//
void ECT_Init(void)
{
TSCR2=0x06; //禁止溢出中断,分频系数 64(24/64MHz)
TIOS_IOS2=0; //通道 2 为输入捕捉
TIOS_IOS3=0; //通道 2 为输入捕捉
TCTL4=0xD0; //3通道捕捉上升沿 2通道捕捉上升下降沿
TIE_C3I=1; //通道 3 输入捕捉中断允许
TIE_C2I=1; //通道 2 输入捕捉中断允许
TSCR1=0x80; //使能定时器
}
#pragma CODE_SEG NON_BANKED //定时器通道 2 输入捕捉中断
void interrupt 11 Timer0_Onput(void)
{
TFLG1_C3F=1;
i++;
length[i]=length2;
switch(i)
{
case 2:result=length[2]-length[1];
LCD_Write_Num(26,1,result,4);
break;
case 4:result=length[4]-length[3];
LCD_Write_Num(26,2,result,4);
break;
case 6:result=length[6]-length[5];
LCD_Write_Num(26,3,result,4);
break;
default:break;
}
}
#pragma CODE_SEG DEFAULT
#pragma CODE_SEG NON_BANKED //定时器通道 3 输入捕捉中断
void interrupt 10 Timer1_Onput(void)
{
TFLG1_C2F=1;//清中断
LCD_Write_Num(32,5,Input_Num,1);
Input_Num++;
if(Input_Num>=4)
{
length2++;
Input_Num=0;
}
}
#pragma CODE_SEG DEFAULT
void main(void) {
/* put your own code here */
PLL_Init();
ECT_Init();
PORT_Init();
LCD_Init(); //初始化液?
LCD_Write_String(0,0,"L of tunnel: ");
LCD_Write_String(0,1,"T1: mm");
//LCD_Write_Num(26,1,length2,3);
LCD_Write_String(0,2,"T2: mm");
//LCD_Write_Num(26,2,Dis,3);
LCD_Write_String(0,3,"T3: mm");
//LCD_Write_Num(26,3,Dis,3);
LCD_Write_String(0,4,"Tunnel State:");
LCD_Write_Num(32,5,i,1);
EnableInterrupts;
for(;;) {
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2