完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
还请帮忙看一下我的代码,(并非原创)
#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的库文件 |
|
相关推荐
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
2109 浏览 0 评论
1275 浏览 1 评论
3971 浏览 2 评论
2887 浏览 0 评论
这是汽车360全景控制器上的主板,请问圆圈中的原件是什么,起什么作用?
2636 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 09:31 , Processed in 0.612337 second(s), Total 71, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号