HC(S)12: How to programm a interrupt in C???

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

HC(S)12: How to programm a interrupt in C???

9,211 次查看
ChrisLambert
Contributor I
Hi to everyone,
 
actually I'm new to the Motorola Microcontrollers, but I've to work around with a HCS12.
My first steps where connecting a LCD and using the AD-Converter. As an extra feature I implemented a Button?
But here is my probleme:
I tried to write a Interrupt Routine for Button, that means, when the button is pushed the interrupt should be released, but somehow it doesn't work?!
For further information:
The button is connected to PORT T (I/O Timer) and should occur at a falling edge.
 
Here is my interrupt Routine:
 
in the main function I implemented:
    TIOS &= ~(1<<5);   // configure Pin 5 as capture input
    TCTL3 = 0xAA;       //not sure if this is right, want to configure PIN reacting on
    TCTL4 = 0xAA;       // a falling edge
    TIE |= (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7);
                                  //enable interrupt for a pins
 
when the button is pushed a interrupt should occur, here is the routine:
void INTERRUPT BUTTON_ISR(void)
{
 PTT = 0x01;  //for testing, a LED connected to PTT should flash
 delay();
 delay();
 delay();
 PTT=0x00;
}
 
after all; I activated the IRQ in the Vector.s table:
 
    .word DEF_IRQ /*ATD1_ISR */  /* 0xFFD0 ATD1*/
    .word DEF_IRQ /*ATD0_ISR */  /* 0xFFD2 ATD0*/
    .word SCI1_ISR   /* 0xFFD4 SCI1*/
    .word SCI0_ISR   /* 0xFFD6 SCI0*/
    .word DEF_IRQ        /* 0xFFD8  SPI0                      */
    .word DEF_IRQ        /* 0xFFDA  Pulse acc input edge      */
    .word DEF_IRQ        /* 0xFFDC  Pulse acc A overflow      */
    .word DEF_IRQ        /* 0xFFDE  Timer overflow            */
    .word DEF_IRQ        /* 0xFFE0  Timer channel 7           */
    .word DEF_IRQ        /* 0xFFE2  Timer channel 6           */
    .word BUTTON_ISR        /* 0xFFE4  Timer channel 5           */
    .word DEF_IRQ        /* 0xFFE6  Timer channel 4           */
    .word DEF_IRQ        /* 0xFFE8  Timer channel 3           */
    .word DEF_IRQ        /* 0xFFEA  Timer channel 2           */
    .word DEF_IRQ        /* 0xFFEC  Timer channel 1           */
 
I'm not sure if this is alright, but perhaps anyone can help me?!
 
Thanks a lot....
 
标签 (1)
0 项奖励
回复
2 回复数

905 次查看
ChrisLambert
Contributor I

Thanks a lot for your answer, but I got it working today...

First I config the PORT I connected the button, let the timer run, configured the PIN to detect falling edge and capture input.

After all, I wrote the vector.s the name of the interrupt function.

In the interrupt function is reseted the "interrupt occured" bit.........

0 项奖励
回复

905 次查看
rhinoceroshead
Contributor I
First of all, this is not how the input capture on the timer is intended to be used, but it can work.  I would go for the IRQ pin or the keyboard interrupts instead of the timer.  The IRQ is the simplest.
 
There is more than one way to do interrupts in C.  Here is the way I do it:
 
First of all, you have to enable interrupts in your main program with a line like this:
 
asm cli;
 
They start out being disabled, so you have to do this to get them to work.
 
In the C file, I do it like this:
 
#pragma TRAP_PROC
void myISR() {
  clearFlagThatCausedInterrupt();
  doSomeStuff();
}
 
Now find the *.prm file for the project and add a line at the end like this:
 
VECTOR 13 myISR   /* Serial receive vector */
 
alternatively you can do this:
 
VECTOR ADDRESS 0xFFFD myISR
 
The vector number is the nth vector counting backwards from FFFE:FFFF, starting from 0.
 
FFFE:FFFF = vector 0
FFFC:FFFD = vector 1
 
etc.
 
You can ignore the vector.s table.
 
The #pragma TRAP_PROC tells the compiler to end the function with an RTI instruction instead of an RTS.
 
The VECTOR 13 myISR will write the address of the function, myISR() into the 13th vector.  That's all that needs to happen for it to work, provided that the interrupt source is configured correctly.

Message Edited by rhinoceroshead on 2006-07-26 03:47 PM

0 项奖励
回复