void main()
{
while (1U)
{
Vrms = Read_Vrms();
SendLWord(Vrms,8,10);SendChar(0x0A);SendChar(0x0D);
Delay_ms(100);
}
}
/* End user code. Do not edit comment generated here */
}
/* Start user code for adding. Do not edit comment generated here */
void Init_ADE7763()
{
SPIWrite1Byte_ADE7763(0x0F|0x80,0x00);
NOP();NOP();NOP();NOP();NOP();
NOP();NOP();NOP();NOP();NOP();
SPIWrite2Byte_ADE7763(0x09|0x80,0x000C);
NOP();NOP();NOP();NOP();NOP();
NOP();NOP();NOP();NOP();NOP();
SPIWrite2Byte_ADE7763(0x0A|0x80,0x0010);
NOP();NOP();NOP();NOP();NOP();
NOP();NOP();NOP();NOP();NOP();
}
//=======================================================================================
unsigned long int Read_Vrms()
{
unsigned char i,j;
unsigned long int Vrms_temp,Vrms_Cal;
unsigned long int Sum_Vrms,Avg_Total,Temp_Vrms,Vrms_Final[6];
unsigned int Rstatus;
Sum_Vrms = 0;
for(j=0;j<5;j++)
{
for(i=0;i<100;i++)
{
do
{
Rstatus = SPIRead2Byte_ADE7763(0x0C);
Rstatus = (Rstatus & 0x001F);
}while(Rstatus == 0x0010);
Temp_Vrms = SPIRead3Byte_ADE7763(0x17);
NOP();NOP();NOP();NOP();
Sum_Vrms = Sum_Vrms + Temp_Vrms;
}
Avg_Total = (Sum_Vrms/100);
Vrms_Final[j] = Avg_Total;
Sum_Vrms = 0;
}
Vrms_temp = Vrms_Final[3];
Rstatus = SPIRead2Byte_ADE7763(0x0C);
return Vrms_temp;
}