ABL electronic PIC16 Personal Computer User Manual


 
Interrupts
Interrupts can be easily handled by means of reserved word interrupt. mikroC
implictly declares function interrupt which cannot be redeclared. Its prototype is:
void interrupt(void);
Write your own definition (function body) to handle interrupts in your application.
mikroC saves the following SFR on stack when entering interrupt and pops them
back upon return:
PIC12 and PIC16 family:
W, STATUS, FSR, PCLATH
PIC18 family: FSR (fast context is used to save WREG, STATUS, BSR)
Note: mikroC does not support low priority interrupts; for PIC18 family, interrupts
must be of high priority.
Function Calls from Interrupt
You cannot call functions from within interrupt routine, but you can make a
function call from embedded assembly in interrupt. For this to work, the called
function (
func1 in further text) must fulfill the following conditions:
1.
func1 does not use stack (or the stack is saved before call, and restored after),
2. func1 must use global variables only.
The stated rules also apply to all the functions called from within
func1.
Note: mikroC linker ignores calls to functions that occur only in interrupt assem-
bler. For linker to recognize these functions, you need to make a call in C code,
outside of interrupt body.
Here is a simple example of handling the interrupts from TMR0 (if no other
interrupts are allowed):
void interrupt() {
counter++;
TMR0 = 96;
INTCON = $20;
}
//~
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
34
MikroElektronika:
Development
tools
-
Books
-
Compilers
page