几个定义
EEPROM_EXT unsigned char TempBufOfMain[258];
typedef struct instantx
{
unsigned char voltagex[4];
unsigned char currentx[4];
unsigned char current1x[4];
unsigned char KWx[4];
unsigned char Tvoltagex[5];
unsigned char FTvoltagex[5];
unsigned char TKWx[6];
unsigned int TNx;
unsigned char FTKWx[6];
unsigned int FTNx;
};
ENERGY_EXT struct instantx instant;
函数1
void ReadFastInstanat(void)
{
memcpy_c(&instant.voltage[0], &instant.voltagex[0],4);
memcpy_c(&instant.activepower[0], &instant.KWx[0],4);
if(!(instant.TNx==0xffff))
{
instant.TNx++;
TempBufOfMain[0]=instant.Tvoltagex[0];
TempBufOfMain[1]=instant.Tvoltagex[1];
TempBufOfMain[2]=instant.Tvoltagex[2];
TempBufOfMain[3]=instant.Tvoltagex[3];
TempBufOfMain[4]=instant.Tvoltagex[4];
TempBufOfMain[10]=0;
TempBufOfMain[11]=instant.voltagex[0];
TempBufOfMain[12]=instant.voltagex[1];
TempBufOfMain[13]=instant.voltagex[2];
TempBufOfMain[14]=instant.voltagex[3];
BcdAdd(&TempBufOfMain[10],TempBufOfMain,instant.Tvoltagex,5);
TempBufOfMain[0]=instant.TKWx[0];
TempBufOfMain[1]=instant.TKWx[1];
TempBufOfMain[2]=instant.TKWx[2];
TempBufOfMain[3]=instant.TKWx[3];
TempBufOfMain[4]=instant.TKWx[4];
TempBufOfMain[5]=instant.TKWx[5];
TempBufOfMain[9]=0;
TempBufOfMain[10]=0;
TempBufOfMain[11]=instant.KWx[0];
TempBufOfMain[12]=instant.KWx[1];
TempBufOfMain[13]=instant.KWx[2];
TempBufOfMain[14]=instant.KWx[3];
BcdAdd(&TempBufOfMain[9],TempBufOfMain,instant.TKWx,6);
}
函数2
u8 BcdAdd(u8 *AddendPnt,u8 *AugendPnt,u8 *SumPnt,u8 Length)
{
u8 i;
u8 Sign=0;
u8 TempVar;
AddendPnt=AddendPnt+Length-1;
AugendPnt=AugendPnt+Length-1;
SumPnt=SumPnt+Length-1;
for(i=0;i<Length;i++)
{
//处理低位
*SumPnt=Sign;
*SumPnt+=(*AddendPnt&0x0f);
*SumPnt+=(*AugendPnt&0x0f);
if(*SumPnt>0x09)
{
*SumPnt+=0x06;
*SumPnt&=0x0f;
TempVar=1;
}
else
TempVar=0;
//处理高位
TempVar+=(*AddendPnt>>4);
TempVar+=(*AugendPnt>>4);
if(TempVar>0x09)
{
TempVar+=0x06;
Sign=1;
}
else
Sign=0;
*SumPnt+=(TempVar<<4);
SumPnt--;
AddendPnt--;
AugendPnt--;
}
return Sign;
}
我想问的是 函数2实现了什么功能,求大侠指点
|