void com_interrupt(void) interrupt 4 using 3 { unsigned char RECEIVR_buffer; if(RI) //处理接收中断 { RI=0; //清除中断标志位 RECEIVR_buffer=SBUF; //接收串口数据 intlen++; //记录读数据次数 if (intlen<3) stabuffer[sta++]=RECEIVR_buffer; else { if ((stabuffer[0]==0xf9)&&(stabuffer[1]==0xae)) { sta=0; switch(intlen) { case 3: pagnum=RECEIVR_buffer; check=check^pagnum; break; case 4: Hdatalen=RECEIVR_buffer; check=check^Hdatalen; break; case 5: Ldatalen=RECEIVR_buffer; check=check^Ldatalen; datalen=Hdatalen*256+Ldatalen; break; default: stadata=1; break; } while (stadata) { if ((intlen-6)<datalen) { buffer=RECEIVR_buffer; check=check^RECEIVR_buffer; inton=1; //WriteBuffer((intlen-6),buffer); } else { parcheck=RECEIVR_buffer; //check=check^parcheck; intlen=0; cStart=0; } stadata=0; }
} else P3_5=0; } } else if (TI) //处理发送中断 { TI=0; } //EA=1; //开中断 }
P3_5=0; UART_init(); //初始化串口 EA=1; //开中断 COM_send(); //发送起始数据包 P3_5=1; while(1) { if (cStart) { if (intlen>5) { writeadd=intlen-6; writedata=buffer; if (inton=1) { WriteBuffer(writeadd,writedata); inton=0; } _nop_(); } } } 我用WriteBuffer();函数把接收到的数据存入一个Flash的Buffer中,但是我读出来的数据和发送的数据不一致,我怀疑是我在调用WriteBuffer()函数时,中断改变了子函数的参数,使得数据发生了变化。请各位兄弟帮帮忙,如何改正。 |