HC(S)12: How to programm a interrupt in C???
07-26-2006
06:17 AM
9,469件の閲覧回数

ChrisLambert
Contributor I
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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);
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;
}
{
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 */
.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....
2 返答(返信)
07-28-2006
09:36 AM
1,163件の閲覧回数

ChrisLambert
Contributor I
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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.........
07-26-2006
08:41 PM
1,163件の閲覧回数

rhinoceroshead
Contributor I
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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
