views:

399

answers:

4

I just finished up my Microprocessors class in college just a few weeks ago, there we programmed in assembly only. We learned a fair amount (IMHO) about interrupts.

Here is my question: I am programming in C using the HiTech Compiler for the 16F684, in the datasheet section discussing the interrupts (PIC 16F684 Datasheet Section 12.4) it says that the program will go to the interrupt vector 0x0004. Using the assembly in my microprocessors class we would simply setup a .org statement pointing to that address and write the needed assembly below so when the interrupt occurs it would jump there and run. I can figure that out in assembly, but when I program in C I don't believe I have control over where program pieces are placed in memory, which presents a problem. I can't figure out how to place commands at the interrupt in C.

Please let me know if I need to clarify!

+1  A: 

You'll have to dig into the HiTech documentation, but often compilers have special keywords to define interrupt functions. The compiler, or the runtime system, has to deal with a function called by an interrupt specially: In addition to setting up the vector, the compiler (or runtime system) has to preserve all the registers. It might not have to do that for a normal, non-interrupt, function.

The manual will be your friend.

Richard Pennington
Thank you for reminding me about the manual, for some reason I wasn't thinking something as simple as that would be in the manual...LOL
onaclov2000
+3  A: 

HiTech C extends the C language with the interrupt function type:

void interrupt my_interrupt_handler (void) {
    handle_interrupts_here();
}

You really should get the manual for the compiler. I believe the manual for the Pic-lite is free for download, at least it was when I downloaded my copy some time in 2001.

slebetman
I'll have to give that a try. That statement is plug and play in the respect that if I have a function called handle_interrupts_here I can deal with them, or does "interrupt" get replaced with a type of interrupt per se?
onaclov2000
PIC16 has only 1 'type' of interrupt. It's up to you to check the registers (HiTech defines them as global variables, check out the header files) to find out what happened.
slebetman
+2  A: 

This FAQ by Microchip has some information about using interrupts under HiTech C.

mdm
It looks like the link you gave gives a good example as well. Thank you
onaclov2000
I used the link you provided and got a test running, (just turning on an LED when the interrupt was hit). Thank you!
onaclov2000
A: 

The CCS compiler for PICs uses #INT_* compiler directives or 'attributes' on interrupt handling functions for the various interrupt sources.

kenny