AT89C51RD2单片机的Modbus+Uart通讯+相序异常检测算法仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
#include "include.h"
//-------------------------------------------------
int cnt_2ms=0;
int cnt_4ms=0;
int cnt_100ms=0;
//------------------------------------------------------------------
void main()
{
init_serialcomm();
ModbusInit(&ModbusReg);
UserInit();
SinTab_Init_Func(&SinTabReg);
TestOldPhaseSeq = 0;
TestPhaseSeqCnt = 0;
while(1)
{
GegSinTab_Func(&SinTabReg);
GetDataForGraph(&ModbusReg);
//---------------
cnt_2ms++;
if(cnt_2ms>=2)
{
cnt_2ms=0;
ForModbusTimerTick(&ModbusReg);
}
//----------------
cnt_4ms++;
if(cnt_4ms>=4)
{
cnt_4ms=0;
modbusTx(&ModbusReg);
}
//------------------
cnt_100ms++;
if(cnt_100ms>=10)
{
cnt_100ms=0;
SciModbus(&ModbusReg);
TestPhaseSeqCnt = GM_Negative_Phase_Sequence_Detect_Ex(&TestOldPhaseSeq,SinTabReg.CosRef[AB],SinTabReg.CosRef[BC],SinTabReg.CosRef[CA]);
}
}
}
//------------------------------------------------------------------------
全部资料51hei下载地址:
见2楼
|