实话说,我确实是看不懂串口接收中断的代码,不知道是怎么用的。有那位大老有经验请教下吗?
uint8_t EUSART1_Read(void)
{
uint8_t readValue = 0;
while(0 == eusart1RxCount)
{
}
eusart1RxLastError = eusart1RxStatusBuffer[eusart1RxTail];
readValue = eusart1RxBuffer[eusart1RxTail++];
if(sizeof(eusart1RxBuffer) <= eusart1RxTail)
{
eusart1RxTail = 0;
}
PIE3bits.RC1IE = 0; //USART接收中断启用位 0:关闭,阻塞的方式是手动把中断启用位置1,置0
eusart1RxCount--;
PIE3bits.RC1IE = 1; //1开启
return readValue;
}
/*接收中断函数*/
void EUSART1_Receive_ISR(void)
{
eusart1RxStatusBuffer[eusart1RxHead].status = 0;
if(RC1STAbits.FERR){
eusart1RxStatusBuffer[eusart1RxHead].ferr = 1;
EUSART1_FramingErrorHandler();
}
if(RC1STAbits.OERR){
eusart1RxStatusBuffer[eusart1RxHead].oerr = 1;
EUSART1_OverrunErrorHandler();
}
if(eusart1RxStatusBuffer[eusart1RxHead].status){
EUSART1_ErrorHandler();
} else {
EUSART1_RxDataHandler();
}
// or set custom function using EUSART1_SetRxInterruptHandler()
}
/*中断回调函数*/
void EUSART1_RxDataHandler(void){
// use this default receive interrupt handler code
eusart1RxBuffer[eusart1RxHead++] = RC1REG; //把接收的字符存入数组
if(sizeof(eusart1RxBuffer) <= eusart1RxHead) //如果缓冲区溢出,则清零忽略
{ //sizeof(数组名),代表整个数组的存//下标数组名,sizeof(eusart1RxBuffer) 字节数
eusart1RxHead = 0;
}
eusart1RxCount++;
} |