Problems creating a simple ISR

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Problems creating a simple ISR

跳至解决方案
2,674 次查看
BFarner
Contributor I
Using CodeWarrior 5.7.0 with an MC9S12DT256, I'm having trouble creating a simple timer interrupt. When running the following code under all three memory models, I get ILLEGAL_BP error and execution halts before the ISR ever runs. What do I need to do to get an ISR working?


#include       /* common defines and macros */
#include      /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dt256b"

void tim_init (void) {
 TIE = 0x01;    // Enable Tim Ch. 0
 TSCR1 = 0x80;   // Enable Timer module
 TSCR2 = 0x80;
 TC0 = 0x0080;
}

void main(void) {
  /* put your own code here */
 
 
  DDRA = 0xFF;
  PORTA = 0x00;
 
  EnableInterrupts;
 
  tim_init();
  for(;;) {} /* wait forever */
  /* please make sure that you never leave this function */
}

#pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt 8 void tim_ch0_vector(void) {
  PORTA = 0x55;
  TFLG2 = 0x80;
}
#pragma CODE_SEG DEFAULT
标签 (1)
标记 (1)
0 项奖励
1 解答
664 次查看
J2MEJediMaster
Specialist I
I'm not quite sure about using the ISR function declaration to set the interrupt vector number. I'd rather see:

#pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt void tim_ch0_vector(void) {
PORTA = 0x55;
TFLG2 = 0x80;
}
#pragma CODE_SEG DEFAULT

You're also not adding the final ingredient to the mix, which is to plug the interrupt's address into the interrupt vector table. If you're using the CW stationery, this table is located in the file vector.c. In that file, do the following:

1) Declare your ISR

extern void near tim_ch0_vector(void); // Declare code of ISR to be somewhere else

2) Add address to vector table in vector.c

const tIsrFunc_vec[] @0xFF80 = {

UnimplementedISR, // vector 63
UnimplementedISR, // vector 62
...
UnimplementedISR, // vector 9
tim_ch0_vector(), // vector 8 // Where the processor is to go for this int
UnimplementedISR, // vector 7
...


Good luck!

---Tom

在原帖中查看解决方案

0 项奖励
2 回复数
665 次查看
J2MEJediMaster
Specialist I
I'm not quite sure about using the ISR function declaration to set the interrupt vector number. I'd rather see:

#pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt void tim_ch0_vector(void) {
PORTA = 0x55;
TFLG2 = 0x80;
}
#pragma CODE_SEG DEFAULT

You're also not adding the final ingredient to the mix, which is to plug the interrupt's address into the interrupt vector table. If you're using the CW stationery, this table is located in the file vector.c. In that file, do the following:

1) Declare your ISR

extern void near tim_ch0_vector(void); // Declare code of ISR to be somewhere else

2) Add address to vector table in vector.c

const tIsrFunc_vec[] @0xFF80 = {

UnimplementedISR, // vector 63
UnimplementedISR, // vector 62
...
UnimplementedISR, // vector 9
tim_ch0_vector(), // vector 8 // Where the processor is to go for this int
UnimplementedISR, // vector 7
...


Good luck!

---Tom
0 项奖励
664 次查看
bigmac
Specialist III

Hello,

Using the ISR function declaration to set the interrupt vector number appears to be valid for the 9S08 (see AN2616 page 53) - but not sure about the 9S12.  The method avoids the need to modify the .PRM file with the vector information.

Regards,
Mac