11.07.2015 Views

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C Language FeaturesInterrupt Handling in C3.10.1 Interrupt FunctionsThe function qualifier interrupt may be applied to any number of C function definitions to allowthem to be called directly from the hardware interrupts. The compiler will process the interruptfunction differently to any other functions, generating code to save and restore any registers usedand exit using the appropriate instruction.If the DSPICC option --STRICT is used, the interrupt keyword becomes __interrupt.An interrupt function must be declared as type void interrupt and may not have parameters.This is the only function prototype that makes sense for an interrupt function. interruptfunctions may not be called directly from C code (due to the different return instruction that is used),but they may call other functions itself.As there is more than one vector location usable with <strong>dsPIC</strong>s, an indicator is required with thefunction definition to specify the interrupt vector to which the function should associated. Thistakes the form of a @ symbol followed by the vector address at the end of the function prototype.The address can either be a literal, or a symbolic name defined after including .An example of an interrupt function linked to the Timer 1 vector (0x0C) is shown here.int tick_count;void interrupt tc_int(void) @ T1_VCTR{++tick_count;}A table of all available vector address macros is shown in Table 3.7, however not all these macrosare available on all devices.Table 3.7: Interrupt Vector Address MacrosMacro name Vector address DescriptionINT0_VCTR 0x14 External Interrupt 0IC1_VCTR 0x16 Input Capture 1OC1_VCTR 0x18 Output Compare 1T1_VCTR 0x1A Timer 1IC2_VCTR 0x1C Input Capture 2OC2_VCTR 0x1E Output Compare 2T2_VCTR 0x20 Timer 2T3_VCTR 0x22 Timer 3SPI1_VCTR 0x24 Serial Comms 1continued. . .47

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!