首先取决于你用的是什么编译器,pic18系列一般有两个,一个个hi-tech c compiler,一个是
c18.要是htc的这样写:
/******************************************************************************/
/* Interrupt Routines */
/******************************************************************************/
/* High-priority service */
void interrupt high_isr(void)
{
/* This code stub shows general interrupt handling. Note that these
conditional statements are not handled within 3 seperate if blocks.
Do not use a seperate if block for each interrupt flag to avoid run
time errors. */
#if 0
/* TODO Add High Priority interrupt routine code here. */
/* Determine which flag generated the interrupt */
if(
{
}
else if (
{
}
else
{
/* Unhandled interrupts */
}
#endif
}
/* Low-priority interrupt routine */
void low_priority interrupt low_isr(void)
{
/* This code stub shows general interrupt handling. Note that these
conditional statements are not handled within 3 seperate if blocks.
Do not use a seperate if block for each interrupt flag to avoid run
time errors. */
#if 0
/* TODO Add Low Priority interrupt routine code here. */
/* Determine which flag generated the interrupt */
if(
{
}
else if (
{
}
else
{
/* Unhandled interrupts */
}
#endif
}
c18的这样写,我这个不是PIC18f452,中断向量的地址可能不对,你对照下数据手册
/** I N T E R R U P T S V E C T O R *****************************************/
//------------------------------------------------------------------------------
// High priority interrupt vector
#pragma code InterruptVectorHigh = 0x08
void interrupt_at_InterruptVectorHigh (void)
{
_asm
GOTO InterruptServiceHigh
_endasm
}
//------------------------------------------------------------------------------
// Low priority interrupt vector
#pragma code InterruptVectorLow = 0x18
void interrupt_at_InterruptVectorLow (void)
{
_asm
GOTO InterruptServiceLow
_endasm
}
/** I N T E R R U P T S S E R V I C E S *************************************/
// -----------------------------------------------------------------------------
// High priority interrupt routine
#pragma interrupt InterruptServiceHigh
void InterruptServiceHigh(void)
{
// Check to see what caused the interrupt
// (Necessary when more than 1 interrupt at a priority level)
// Check for INT0 interrupt
#if 0
/* TODO Add High Priority interrupt routine code here. */
/* Determine which flag generated the interrupt */
if(
{
}
else if (
{
}
else
{
/* Unhandled interrupts */
}
#endif
}
// -----------------------------------------------------------------------------
// Low priority interrupt routine
#pragma interruptlow InterruptServiceLow
void InterruptServiceLow(void)
{
/* This code stub shows general interrupt handling. Note that these
conditional statements are not handled within 3 seperate if blocks.
Do not use a seperate if block for each interrupt flag to avoid run
time errors. */
#if 0
/* TODO Add Low Priority interrupt routine code here. */
/* Determine which flag generated the interrupt */
if(
{
}
else if (
{
}
else
{
/* Unhandled interrupts */
}
#endif
}
这些中断函数都要先声明