做RS485通信,485总线上的干扰大了之后,PIC单片机死在中断里,是什么情况?
void interrupt clkint() { if(RCIE&&RCIF) { if(OERR||FERR) { SPEN=0; CREN=0; recdata_error=RCREG; CREN=1; SPEN=1; } else receive_ok=1; if(receive_ok==1) //接收数据中断 { receive_ok=0; recdata[recbyte_num1]=RCREG; recbyte_num1++; if((recdata[0]==0XA5)||(recdata[0]==0X0A)) { ucharj; if((recbyte_num1>3)&&(recbyte_num1==recdata[2]+2)) { CREN=0; if(recbyte_num1<14) { for(j=recbyte_num1;j<14;j++) recdata[j]=0; } cheaksum=recdata[2]+recdata[3]+recdata[4]+recdata[5]+recdata[6]+recdata[7]+recdata[8]+recdata[9]+recdata[10]+recdata[11]+recdata[12]+recdata[13]; if(cheaksum==0) a=1; recbyte_num1=0; } if(a==1) { a=0; …… } CREN=1; } else recbyte_num1=0; } } asm("CLRWDT"); //收到干扰死在中断中,没办法,加了个看门狗,但不是解决问题的根本方法 if(TMR1IF==1) { TMR1IF=0; //TMR1中断标志位清0 TMR1L=0XDB; TMR1H=0X0B; //赋初始值 con250ms++; if(con250ms>=2) { con250ms=0; con500ms++; } } }
|