void sendwframe(void) { unsigned char data i; b-rightMeterFrame=0; RDCTP- command-table[13]=0x43; RDCTP-command-table[14]=0xc3; RDCTP-command-table [15]=0x44; RE-DE=1; for(i=0;i<17;i++) { SBUF= RDCTP-command-table [i]; delay(); } RE-DE=0; b-timerOver=0; countex-10ms=0x00; ET0=1; TR0=1 Do { if(b-tirnerOver) TR0=0; ET0=0; b-timerOver=0; counter-10ms=0x00; RE-DE=1; m-meterAddrC=0x00; RS485-status=0x00; b-rightMeterFrame=0; return; } }while(b-rightMeterFrame != 1); RE-DE=1; } //以中断方式通过RS-485接口从电表接收数据帧 com-isp(void) interrupt 4 using 1 if(RI) { RI=0; RS485-data=SBUF; if(RS485-status == 0x00) if(RS485-data==meter-address-return[m-meterAddrC]) { m-metcrAddC=0x00; } else { m-meterAddrC=0x00; } if(m-meterAddrC == 11) { m-meterAddrC=0x00; RS485-status=0x01; } else if(RS485-status == 0x01) { if(RS485-data != 0x68) { RS485-status=0x00; m-metcrAddrC=0x00; } else { RS485-status=0x02; } } else if(RS485-status=0x02) { m-meterCtrCode=RS485-data; RS485-status=0x03; } else if(RS485-status==0x03) { m-meterDatLen=RS485-data; m-meterDataC=0x00; RS485-status=0x04; } else if(RS485-status==0x04) { m-meterDatBuf[m-meterDataC]=RS485-data; m-meterDataC++; if(m-meterDataC==m-meterDatLen) { m-meterSysCheck=0xD3; RS485-status=0x05: } else if(RS485-status==0x05) { m-meterCheck=RS485-data; //准备对接收的数据进行累加和校验 m-meterSysCheck+=0x68; m-meterSysCheck+=m-meterCtrCode; m-meterSysCheck+=m-meterDatLen; if(m-meterDatLen!=0x00) { for(m-meterDataC=0;m-meterDataC<m-meterDatLen;mmeterDataC++) { m-meterSysCheck+=m-meterDatBuf[m-meterDataC]; } if(m-meterCheck!=mLneterSysCheck) { m-meterAddrC=0x00; RS485 status=0x00; } else { m-meterEndC=0x00; RS485-status=0x06; } } else if(RS485-status=0x06) { if(RS485-data!=0x16) I m-meterAddrC=0x00; RS485 status=0x00; } else { m-meterEndC++; } if(m-meterEndC=0x02) { b-rightMeterFrame=1; RE-DE=1; m-meterAddrC=0x00; RS485 status=0x00; } } } if(T1) { TI=0; } }