Board logo

标题: 中断在dg128B中能运行,为什么在hz64中不能呢? [打印本页]

作者: fjczd    时间: 2008-12-10 17:16     标题: 中断在dg128B中能运行,为什么在hz64中不能呢?

为什么我把这个程序放到s12hz64里,却进不去中断呢?当然声明部分我是做了修改的
程序如下:
#include <hidef.h> /* common defines and macros */
#include <MC9S12HZ64.h> /* derivative information */
//#pragma LINK_INFO DERIVATIVE "MC9S12HZ64"

int intcount = 0;
void timer_init(void)
{
TSCR2_PR0 = 1; //prescale factor is 128
TSCR2_PR1 = 1;
TSCR2_PR2 = 1;
TSCR2_TOI = 1; //overflow enable
TFLG2_TOF = 1;
TSCR1_TEN = 1; //timer enable
}


#pragma CODE_SEG NON_BANKED
interrupt 16 void timer_interrupt_handle(void)
{
intcount++;
TFLG2_TOF = 1; //clear interrupt flag
};
#pragma CODE_SEG DEFAULT

void main(void)
{
EnableInterrupts;
timer_init();
for(;;) {}
}

dg128b的程序如下,这个可以仿真,看到intcount在不断增加

程序如下

#include <hidef.h> /* common defines and macros */

#include <mc9s12dg128.h> /* derivative information */

#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"

int intcount = 0;

void timer_init(void)

{

TSCR2_PR0 = 1; //prescale factor is 128

TSCR2_PR1 = 1;

TSCR2_PR2 = 1;

TSCR2_TOI = 1; //overflow enable

TFLG2_TOF = 1;

TSCR1_TEN = 1; //timer enable

}

#pragma CODE_SEG NON_BANKED

interrupt 16 void timer_interrupt_handle(void)

{

intcount++;

TFLG2_TOF = 1; //clear interrupt flag

};

#pragma CODE_SEG DEFAULT

void main(void)

{

EnableInterrupts;

timer_init();

for(;;) {}

}


作者: strongchen    时间: 2008-12-10 17:33

看看DG128与HZ64的中断矢量地址是否有所不同。
作者: fjczd    时间: 2008-12-11 09:24

QUOTE:
以下是引用strongchen在2008-12-10 17:33:00的发言:
看看DG128与HZ64的中断矢量地址是否有所不同。

上边这个是hz64的,下边这个是dg128的,应该是一致的

#define Vtimpaie 0x0000FFDA

#define Vtimpaovf 0x0000FFDC

#define Vtimovf 0x0000FFDE

#define Vtimch7 0x0000FFE0

#define Vtimch6 0x0000FFE2

#define Vtimch5 0x0000FFE4

#define Vtimch4 0x0000FFE6

#define Vtimch3 0x0000FFE8

#define Vtimch2 0x0000FFEA

#define Vtimch1 0x0000FFEC

#define Vtimch0 0x0000FFEE

#define Vrti 0x0000FFF0

#define VReserved6 0x0000FFF2

#define Vxirq 0x0000FFF4

#define Vswi 0x0000FFF6

#define Vtrap 0x0000FFF8

#define Vcop 0x0000FFFA

#define Vclkmon 0x0000FFFC

#define Vreset 0x0000FFFE

#define Vtimpaie 0x0000FFDA

#define Vtimpaaovf 0x0000FFDC

#define Vtimovf 0x0000FFDE

#define Vtimch7 0x0000FFE0

#define Vtimch6 0x0000FFE2

#define Vtimch5 0x0000FFE4

#define Vtimch4 0x0000FFE6

#define Vtimch3 0x0000FFE8

#define Vtimch2 0x0000FFEA

#define Vtimch1 0x0000FFEC

#define Vtimch0 0x0000FFEE

#define Vrti 0x0000FFF0

#define Virq 0x0000FFF2

#define Vxirq 0x0000FFF4

#define Vswi 0x0000FFF6

#define Vtrap 0x0000FFF8

#define Vcop 0x0000FFFA

#define Vclkmon 0x0000FFFC

#define Vreset 0x0000FFFE


作者: strongchen    时间: 2008-12-11 09:36

看看编译后生成的矢量地址是否与之相符。
作者: fjczd    时间: 2008-12-11 09:51

QUOTE:
以下是引用strongchen在2008-12-11 9:36:00的发言:
看看编译后生成的矢量地址是否与之相符。

这个应该在哪里看呢?不好意思,刚接触,问题问得比较没水平。

我把dg128下可以运行的例子,和在hz下不能进入中断的一起发上来,请帮忙看看吧

谢谢了

[attach]5825[/attach]

[此贴子已经被作者于2008-12-11 9:53:22编辑过]


作者: fjczd    时间: 2008-12-11 09:59

因为我选的芯片是hz64的,上边的这个中断如果能运行,我要运行lvi的中断。

我觉得定时器的这个应该比较简单,如果这个都不能运行,那运行lvi中断恐怕就无从谈起了。还有,不知道版主对lvi中断了解多不多,我下边这么用行不行?

lvi中断如下所示

#include <hidef.h> /* common defines and macros */
#include <MC9S12HZ64.h> /* derivative information */


/*use the LVI interrupt to watch the power supply voltage and store
important data to EEPROM memory if the low voltage is detected. The time
is critical here - the data are supposed to be programmed prior to the
low voltage reset. So, that's not possible if the voltage falls down too
quickly.
In the other words:
If the supply voltage is below the specs (below 4.5V) then the ATD
accuracy and the functionality of input/output pins is affected. The MCU
is still working fine and also we can erase/program the EEPROM or FLASH
memory. The MCU is reset if the voltage is too low - if the supply
voltage is below VLVRA threshold (low voltage reset - assert level)
which is min 2.25V (you can find the specifications - in Appendix A).


Here is simple example how to use LVI interrupt: */

#pragma CODE_SEG NON_BANKED
interrupt 57 void LVI_ISR(void)
{
if(VREGCTRL_LVDS == 1)
{
//the voltage is bellow VLVIA threshold
//store the data to EEPROM here
}
else
{
//the voltage is above VLVID threshold
//do something here if needed
}

VREGCTRL_LVIF = 1; //clear the interrupt flag
}
#pragma CODE_SEG dEFAULT

void main(void)
{
VREGCTRL_LVIE = 1; //enable low voltage interrupt
EnableInterrupts;

//do something here
for(;;){ }
}

[attach]5826[/attach]

[此贴子已经被作者于2008-12-11 9:59:43编辑过]


作者: fjczd    时间: 2008-12-11 10:09

lvi中断在full chip simulation下应该是无法进行仿真的吧?不知道在进行硬件仿真的时候,即TBDML下,直接断电行不行。看有的手册上说,断电时间不能太快,如果太快,恐怕不行。这个断电时间能控制么?
作者: strongchen    时间: 2008-12-11 10:11

建议你不要用中断号的方式定义中断矢量,最好用中断地址的方式,这样不容易出错。可以在PRM文件中这样定义:

VECTOR ADDRESS 0xFFDE timer_interrupt_handle


作者: fjczd    时间: 2008-12-11 10:25

QUOTE:
以下是引用strongchen在2008-12-11 10:11:00的发言:

建议你不要用中断号的方式定义中断矢量,最好用中断地址的方式,这样不容易出错。可以在PRM文件中这样定义:

VECTOR ADDRESS 0xFFDE timer_interrupt_handle

这是软件的缺陷么?还是有什么别的需要注意的地方呢?


作者: strongchen    时间: 2008-12-11 11:49

这并不是什么缺陷,只是用数中断号的方法容易出错而已。
作者: fjczd    时间: 2008-12-11 11:51

多谢了
作者: fjczd    时间: 2008-12-11 12:05

QUOTE:
以下是引用strongchen在2008-12-11 10:11:00的发言:

建议你不要用中断号的方式定义中断矢量,最好用中断地址的方式,这样不容易出错。可以在PRM文件中这样定义:

VECTOR ADDRESS 0xFFDE timer_interrupt_handle

按照这种定义改了,还是不行啊。我觉得这个问题很奇怪,不是软件哪里设置有问题吧

版主抽空看看我的源程序吧,都在附件里。

谢谢了


作者: fjczd    时间: 2008-12-11 15:12

QUOTE:
以下是引用fjczd在2008-12-11 12:05:00的发言:
QUOTE:
以下是引用strongchen在2008-12-11 10:11:00的发言:

建议你不要用中断号的方式定义中断矢量,最好用中断地址的方式,这样不容易出错。可以在PRM文件中这样定义:

VECTOR ADDRESS 0xFFDE timer_interrupt_handle

按照这种定义改了,还是不行啊。我觉得这个问题很奇怪,不是软件哪里设置有问题吧

版主抽空看看我的源程序吧,都在附件里。

谢谢了


作者: fjczd    时间: 2008-12-11 15:13

看来只有版主会上来回复问题啊

呵呵


作者: fjczd    时间: 2008-12-11 15:13

希望问题能得到解决
作者: strongchen    时间: 2008-12-11 16:54

我试过了,程序本身应该没什么问题的。你要看看程序是否真的跑起来了。
作者: fjczd    时间: 2008-12-12 09:42

用的是Full Chip Simulation,可以执行的,就是进不去中断

还有在dg128里的那个程序就可以的,我今天用hz64重新生成了一个工程,还是照旧不能进中断


作者: fjczd    时间: 2008-12-15 09:16

改成4.7版本就可以了,真是很奇怪

时不时hz64的芯片不如dg128的常用,而软件本身也存在bug?


作者: strongchen    时间: 2008-12-16 09:54

软件仿真是经常出现BUG的,因为很多事件需要软件去模拟,去触发。用硬件仿真调试是没有问题的。
作者: fjczd    时间: 2008-12-16 12:16

QUOTE:
以下是引用strongchen在2008-12-16 9:54:00的发言:
软件仿真是经常出现BUG的,因为很多事件需要软件去模拟,去触发。用硬件仿真调试是没有问题的。

可能版本越高,bug也会越少吧






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0