RN8302应用程序V1.3.docx
《RN8302应用程序V1.3.docx》由会员分享,可在线阅读,更多相关《RN8302应用程序V1.3.docx(40页珍藏版)》请在冰豆网上搜索。
typedefunsignedchar u8;
typedefsignedchar s8;
typedefunsignedshort u16;
typedefsignedshort s16;
typedefunsignedlongint u32;
typedefsignedlongint s32;
typedefunsignedshortWORD;
typedef unsignedchar BOOL;
#definePinWrite_ADSCLK(x) ((x)?
(P0_bit.no6=1,PM0_bit.no6=1):
(PM0_bit.no6=0,P0_bit.no6=0)) //
#definePinMode_ADSCLK(x) ((x==GPIO_MODE_OUT)?
(PM0_bit.no6=0):
(PM0_bit.no6=1))
#definePinRead_ADSDI() (P4_bit.no4)
#definePinWrite_ADSDO(x) ((x)?
(P6_bit.no0=1,PM6_bit.no0=1):
(PM6_bit.no0=0,P6_bit.no0=0)) //
#definePinWrite_ADCS(x) ((x)?
(P6_bit.no1=1,PM6_bit.no1=1):
(PM6_bit.no1=0,P6_bit.no1=0))
#definePinWrite_ADRST(x) ((x)?
(P0_bit.no5=1,PM0_bit.no5=1):
(PM0_bit.no5=0,P0_bit.no5=0))
typedefenum{ERROR=0,SUCCESS=!
ERROR}ErrorStatus;
typedefstruct{
// u32Dat:
23;
// u32S:
1;
u8Dat0;
u8Dat1;
u8Dat2:
7;
u8S:
1;
}sDF09;
typedefstruct{
u32Dat;
}sDF11;
typedef sDF11sFsEgSh_TypeDef;
#pragmavector=INTTM01_vect
__interruptvoidMD_INTTM01(void)
{
TMIF01=0; /*INTTM01interruptflagclear*/
SysStamp++;
}
u16fnStamp_Through(u16Ago)
{
externu16 SysStamp;
if(SysStamp>=Ago)
{return(SysStamp-Ago);}
else
{return((0xffff-Ago)+SysStamp);}
}
u16fnHexToBcd_u16(u16Dat)
{
u16Result=0;
Dat=Dat%10000;
Result+=(Dat/1000)*0x1000;
Dat=Dat%1000;
Result+=(Dat/100)*0x100;
Dat=Dat%100;
Result+=(Dat/10)*0x10;
Dat=Dat%10;
Result+=Dat;
return(Result);
}
u32 fnHexToBcd_u32(u32Dat)
{
u32result=0;
Dat=Dat%100000000;
result+=(Dat/10000000)*0x10000000;
Dat=Dat%10000000;
result+=(Dat/1000000)*0x1000000;
Dat=Dat%1000000;
result+=(Dat/100000)*0x100000;
Dat=Dat%100000;
result+=(Dat/10000)*0x10000;
Dat=Dat%10000;
result+=(Dat/1000)*0x1000;
Dat=Dat%1000;
result+=(Dat/100)*0x100;
Dat=Dat%100;
result+=(Dat/10)*0x10;
Dat=Dat%10;
result+=Dat;
return(result);
}
u16fnDFConver_Bcd16To16(s16Dat)
{
u16Result;
Result=abs(Dat)%8000;
Result=fnHexToBcd_u16(Result);
if(Dat<0)Result|=0x8000;
elseResult&=0x7fff;
return(Result);
}
u32fnDFConver_Bcd32To32(s32Dat)
{
u32Result;
Result=labs(Dat)%80000000;
Result=fnHexToBcd_u32(Result);
if(Dat<0)Result|=0x80000000;
elseResult&=0x7fffffff;
return(Result);
}
sDF09fnDFConver_Hex32ToDF09(s32Dat)
{
sDF09 Result;
memset(&Result,0,sizeof(sDF09));
if(Dat<0)Result.S=1;
elseResult.S=0;
Dat=labs(Dat)%800000;
Dat=fnHexToBcd_u32(Dat);
Result.Dat0=Dat;
Result.Dat1=Dat>>8;
Result.Dat2=Dat>>16;
return(Result);
}
typedefunion//公共数据运算区8字节
{
u8ucTempBuf[8];
u32lTemp32;
u16wTemp16;
u8ucTemp8;
}sDl645StruDataComm_TypeDef;
__no_initsDl645StruDataComm_TypeDefDl645RN8302DataComm;
__no_init sDl645FrontTmp_TypeDef Dl645FrontTmp;
__no_init sDl645Front_TypeDef Dl645Front;
__no_init sDl645Eg_TypeDef Dl645Eg;
__no_initsDl645FirmParaFile_TypeDefDl645FirmPara;
typedefstruct
{
u8 ChkErrCnt;//读错误计数1
s32 Pw[12]; //{PaPbPcPQaQbQcQSaSbScS}48
s32 UI[7]; //UaUbUcIaIbIcInal28
s32 VectorU[9]; //正序、负序、零序电压
s32 VectorI[9]; //正序、负序、零序电流
s32 Pf[4]; //PfPfaPfbPfc16
u32 Frequency; //电网频率,单位:
4
s32 YUI[3],YUU[2];//20
s32 Pulse[15]; //前台高频脉冲48
//---电能脉冲---
s32 Pulse_EgTmp[20]; //高频脉冲{P,Q,Ps},{Pa,Qa,Psa},{Pb,Qb,Psb},{Pc,Qc,Psc}{Fp,Fq}{Fpa,Fqa}{Fpb,Fqb}{Fpc,Fqc}
u32 Pulse_Eg[20];//低频脉冲数
//---需量脉冲---
s32 Pulse_NeedTmp[12];
u16 Pulse_Need[12];//{PNeed,QNeed,PsNeed},{PNeeda,QNeeda,PsNeeda},{PNeedb,QNeedb,PsNeedb},{PNeedc,QNeedc,PsNeedc}48
u16 Angle[9];
u16 PDirect;//4
u32 ChkSum1;//4
u32 ChkSum2;//4
u16 Temperature; //温度4
u32 ClockBat; //时钟电池4
u32 BackupBat; //后备电池4
u16CF1DelayStamp;
u16CF2DelayStamp;
u16CfIn_P;
u16CfIn_q;
u16CfTime_P;
u16CfTime_q;
}sDl645FrontTmp_TypeDef;
typedefstruct
{
structsFrontPubData_TypeDef{
u16 U[3]; //---电压---NNN.N6
u16 VectorU[9]; //正序电压0--2负序电压3---5零序电压6---8
u32 I[4]; //---电流NNNN.NNNN(电流值要求3整3小,整定值要求2整4小,最高位表示方向)---16
u32 VectorI[9]; //正序电流0--2负序电流3---5零序电流6---8
sDF09 Pw[12]; //---瞬时有功/无功/视在功率NN.NNNN---{PPaPbPcQQaQbQcSSaSbSc}36
u16 Pf[4]; //---功率因数N.NNN--- 最高位表示方向{PfPfaPfbPfc} 8sDF05
u16 Angle[9]; /