电子元器件论坛
直播中

jf_83840521

5年用户 10经验值
擅长:电源/新能源
私信 关注

我想请问用cs5463这个芯片来获取电流和电压单片机进行处理,但是编程的时候,不知道cs5463的头文件是什么?

还请帮忙看一下我的代码,(并非原创)
#include
#include
#define uint unsigned int
void main()
{
CS5463_Init();
LCM_init();       //初始化液晶显示器
LCM_clr();       //清屏
chn_disp(tab1); //显示欢迎字
DelayM(500);  //显示等留3秒
while(1)
{
  sta= CS5463_GetStatusReg();            //检测中断产生的原因
  if(0x01==(sta&0x01))                    //读取电流电压
  {
   CS5463_ResetStatusReg();            //清除标志
   CS5463_GetVoltRMS();                //获取电压
   CS5463_GetCurrentRMS();                //获取电流
   CS5463_GetPactiveRMS();                //获取功率
  }
  if(0x02==(sta&0x02))                //读取温度
  {   
   CS5463_GetVoltRMS();                //获取电压                                
   CS5463_GetTemperature();            //温度读取不需要太频繁,所以跟电流电压一起读取
   CS5463_Init();                //重新初始化芯片
  }                        
  //SndCom1Data(MeasureData,16);
  }
}
}
static void CS5463_GetVoltRMS(void)        
{
float G = 0.5,result;        //typedef float          fp32;    就是浮点类型
int temp1;              //  int
uint8 temp,i,j;          //  byte
CS5463ReadReg(REG_VRMSR,RX_Buff);           //读取电压有效值   
i = 0;
result = 0;
while(i<3)
{
  temp = RX_Buff;                    
  j = 0;
  while(j<8)
  {
   if(temp&0x80)
   {
    result += G;   
   }
   temp <<= 1;
   j++;
   G = G/2;   
  }
  i++;                                
}                                        //电压在220时取样电压为78mv
result = result*CS5463_VScale;//V_Coff;                //计算电压值220V*250mv/(110mv/1.414)=704.8V    可以暂时不用
result *= 100;                        //单位为mV(毫伏) 12345mv  5位你怎么显示
temp1 = (uint32)result;
LCM_WriteDatOrCom  (0,0x84);
aa=    temp1/10000;
LCM_WriteDatOrCom(1,aa+0x30);
bb=    (temp1%10000)/1000;
LCM_WriteDatOrCom(1,bb+0x30);
cc=(temp1%1000)/100;
LCM_WriteDatOrCom(1,cc+0x30);
LCM_WriteDatOrCom(1,0x2e);
dd=    (temp1%100)/10;
LCM_WriteDatOrCom(1,dd+0x30);
ee=temp1%10;
LCM_WriteDatOrCom(1,ee+0x30);
LCM_WriteString(" V");
}
static void CS5463_GetCurrentRMS(void)
{
fp32 G = 0.5,result;
uint32 temp1;
uint8 temp,i,j;
CS5463ReadReg(REG_IRMSR,RX_Buff);           //读取电流有效值
i = 0;
result = 0;
while(i<3)
{
  temp = RX_Buff;                    
  j = 0;
  while(j<8)
  {
   if(temp&0x80)
   {
    result += G;   
   }
   temp <<= 1;
   j++;
   G = G/2;   
  }
  i++;
}
  result = result*CS5463_IScale;//I_Coff;                        //计算电流值暂时不用
  result *= 1000;                                //单位mA(毫安)  12345ma
  temp1 = (uint32)result;
  LCM_WriteDatOrCom  (0,0x94);
  aa=    temp1/10000;
  LCM_WriteDatOrCom(1,aa+0x30);
  bb=    (temp1%10000)/1000;
  LCM_WriteDatOrCom(1,bb+0x30);
  cc=(temp1%1000)/100;
  LCM_WriteDatOrCom(1,cc+0x30);
  dd=    (temp1%100)/10;
  LCM_WriteDatOrCom(1,dd+0x30);
  ee=temp1%10;
  LCM_WriteDatOrCom(1,ee+0x30);
  LCM_WriteString(" mA");
}
static void CS5463_GetPactiveRMS(void)
{
fp32 G = 1.0,result;
uint8 temp,i,j;
uint32 temp1;
CS5463ReadReg(0x14,RX_Buff);       //读取有功功率REG_Pactive
temp = RX_Buff[0];
if(temp&0x80)                            //如果为负数,计算原码
{
  RX_Buff[0] = ~RX_Buff[0];            //本来为取反+1,这里因为精度的原因,不+1
  RX_Buff[1] = ~RX_Buff[1];
  RX_Buff[2] = ~RX_Buff[2];            
}
i = 0;
result = 0;
while(i<3)
{
  temp = RX_Buff;                    
  j = 0;
  while(j<8)
  {
   if(temp&0x80)
   {
    result += G;   
   }
   temp <<= 1;
   j++;
   G = G/2;   
  }
  i++;
}
result = result*13125;
temp1 = (uint32)result;
LCM_WriteDatOrCom  (0,0x8C);        //26W  12345W
aa=    temp1/10000;
LCM_WriteDatOrCom(1,aa+0x30);
bb=    (temp1%10000)/1000;
LCM_WriteDatOrCom(1,bb+0x30);
cc=(temp1%1000)/100;
LCM_WriteDatOrCom(1,cc+0x30);
dd=    (temp1%100)/10;
LCM_WriteDatOrCom(1,dd+0x30);
ee=temp1%10;
LCM_WriteDatOrCom(1,ee+0x30);
LCM_WriteString(" W");
if(temp1>9)
{
  LED1 = 0;
}
else
{
  LED1 = 1;
}
}
static void CS5463_GetPactiveRMS(void)
{
fp32 G = 1.0,result;
uint8 temp,i,j;
uint32 temp1;
CS5463ReadReg(0x14,RX_Buff);       //读取有功功率REG_Pactive
temp = RX_Buff[0];
if(temp&0x80)                            //如果为负数,计算原码
{
  RX_Buff[0] = ~RX_Buff[0];            //本来为取反+1,这里因为精度的原因,不+1
  RX_Buff[1] = ~RX_Buff[1];
  RX_Buff[2] = ~RX_Buff[2];            
}
i = 0;
result = 0;
while(i<3)
{
  temp = RX_Buff;                    
  j = 0;
  while(j<8)
  {
   if(temp&0x80)
   {
    result += G;   
   }
   temp <<= 1;
   j++;
   G = G/2;   
  }
  i++;
}
result = result*13125;
temp1 = (uint32)result;
LCM_WriteDatOrCom  (0,0x8C);        //26W  12345W
aa=    temp1/10000;
LCM_WriteDatOrCom(1,aa+0x30);
bb=    (temp1%10000)/1000;
LCM_WriteDatOrCom(1,bb+0x30);
cc=(temp1%1000)/100;
LCM_WriteDatOrCom(1,cc+0x30);
dd=    (temp1%100)/10;
LCM_WriteDatOrCom(1,dd+0x30);
ee=temp1%10;
LCM_WriteDatOrCom(1,ee+0x30);
LCM_WriteString(" W");
if(temp1>9)
{
  LED1=0;
}
else
{
  LED1 = 1;
}


错误提示告诉我,没有包含cs5463的库文件



更多回帖

发帖
×
20
完善资料,
赚取积分