Problems creating a simple ISR

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Problems creating a simple ISR

ソリューションへジャンプ
2,693件の閲覧回数
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 解決策
683件の閲覧回数
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 返答(返信)
684件の閲覧回数
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 件の賞賛
返信
683件の閲覧回数
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