开发者

PIC 16F684 Microcontroller Interupt Handling

I just fini开发者_如何学Cshed 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!


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


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜