首先,仔细跟踪到中断总函数interrupt_manager.c中看中断影响的函数名称,比喻我的是这样: if(PIE1bits.RCIE == 1 && PIR1bits.RCIF == 1) {
EUSART_RxDefaultInterruptHandler(); //调用串口接收中断函数。
}
else if(PIE1bits.TMR1IE == 1 && PIR1bits.TMR1IF == 1)
{
TMR1_ISR();
}
else
{
//Unhandled Interrupt
}
然后,在UART.c中查看上面红字中断入口函数的定义:
void EUSART_SetRxInterruptHandler(void (* interruptHandler)(void)){
EUSART_RxDefaultInterruptHandler = interruptHandler;
}
这里定义默认中断函数入口名称,是不是与上面名称对应了?
然后再看uartinit函数里初始化中断函数赋值:
void EUSART_Initialize(void)
{
// disable interrupts before changing states
PIE1bits.RCIE = 0;
EUSART_SetRxInterruptHandler(EUSART_Receive_ISR); //在这里递归赋值命名接收中断函数的名称为“EUSART_Receive_ISR”。即EUSART_RxDefaultInterruptHandler = EUSART_Receive_ISR。
// Set the EUSART module to the options selected in the user interface.
// ABDOVF no_overflow; SCKP Non-Inverted; BRG16 16bit_generator; WUE enabled; ABDEN disabled;
BAUD1CON = 0x0A;
// SPEN enabled; RX9 8-bit; CREN enabled; ADDEN disabled; SREN disabled;
RC1STA = 0x90;
// TX9 8-bit; TX9D 0; SENDB sync_break_complete; TXEN enabled; SYNC asynchronous; BRGH hi_speed; CSRC slave;
TX1STA = 0x24;
// SP1BRGL 103;
SP1BRGL = 0x67;
// SP1BRGH 0;
SP1BRGH = 0x00;
EUSART_SetFramingErrorHandler(EUSART_DefaultFramingErrorHandler);
EUSART_SetOverrunErrorHandler(EUSART_DefaultOverrunErrorHandler);
EUSART_SetErrorHandler(EUSART_DefaultErrorHandler);
RxLastError.status = 0;
// initializing the driver state
TxHead = 0;
TxTail = 0;
TxBufferRemaining = sizeof(TxBuffer);
RxHead = 0;
RxTail = 0;
RxCount = 0;
// enable receive interrupt
PIE1bits.RCIE = 1;
}
然后在接收中断中处理中断状态:
void EUSART_Receive_ISR(void)
{
RxStatusBuffer[RxHead].status = 0;
if(RC1STAbits.FERR){
RxStatusBuffer[RxHead].ferr = 1;
EUSART_FramingErrorHandler(); //错误?
}
if(RC1STAbits.OERR){
RxStatusBuffer[RxHead].oerr = 1;
EUSART_OverrunErrorHandler(); // 溢出错误?
}
if(RxStatusBuffer[RxHead].status){
EUSART_ErrorHandler(); // 接收错误?跳转错误处理。
} else {
EUSART_RxDataHandler(); // 如果正常?则接收数据。
}
// or set custom function using EUSART_SetRxInterruptHandler()
}
看到这,就知道了,实际跳转的接收中断函数名称是EUSART_RxDataHandler();所以,个人代码实际是在EUSART_RxDataHandler这个函数这里添加。
|