English 中文(简体)
PIC 16F684 Microcontroller Interupt Handling
原标题:

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!

最佳回答

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.





相关问题
Is Thread.interrupt() evil?

A teammate made the following claim: "Thread.interrupt() is inherently broken, and should (almost) never be used". I am trying to understand why this is the case. Is it a known best practice ...

HID input report queues on C8051F320

it seems that as soon as data is ready for the host (such as when I use WriteFile to send a command to the HID in which I tell the HID to give back some data such as the port value) and the in packet ...

PIC 16F684 Microcontroller Interupt Handling

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 ...

Callback, specified in QueueUserAPC , does not get called

In my code, I use QueueUserAPC to interrupt the main thread from his current work in order to invoke some callback first before going back to his previous work. std::string buffer; std::tr1::...

kernel software trap handling

I m reading a book on Windows Internals and there s something I don t understand: "The kernel handles software interrupts either as part of hardware interrupt handling or synchronously when a thread ...

How to kill deadlocked threads in Java?

I d like to kill threads that are stuck in deadlock state. First, we can detect thread ids in deadlock state using the findDeadlockedThreads() method of the ThreadMXBean class in java.lang.management. ...

Extended Interrupt 13, Reading an unformatted Disk

It s been a while since I did any ASM, and decided to once again try and write a small bootloader, testing with qemu. My issue is with interupt 13, for some reason the carry flag is being set, so the ...

Java Hardware Interrupt Handling

I would like to know if it is possible to automatically invoke a Java method when a hardware interrupt is raised.

热门标签