接上面
/**********************************************************************************************************
** Function name: Task_Monitor
** Descriptions: UCOS任务
** input parameters: void *pdata
** output parameters: 无
** Returned value: 无
**********************************************************************************************************/
void Task_Monitor(void *pdata)
{
...... //无关代码省略了
char AURms_chars[] = {0,0,0,0,0,0,0};
char BURms_chars[] = {0,0,0,0,0,0,0};
char CURms_chars[] = {0,0,0,0,0,0,0};
char TURms_chars[] = {0,0,0,0,0,0,0};
char AIRms_chars[] = {0,0,0,0,0,0};
char BIRms_chars[] = {0,0,0,0,0,0};
char CIRms_chars[] = {0,0,0,0,0,0};
char TIRms_chars[] = {0,0,0,0,0,0};
char Freq_chars[] = {0,0,0,0,0,0};
//初始化ATT7022EU
printf("\r\nInitializing ATT7022EU...\r\n");
ATT7022_Init();
delay_ms(100);
printf("\r\nATT7022EU initializing Finished!\r\n");
printf("\r\nAdjusting ATT7022EU...\r\n");
ATT_Adjust();
delay_ms(100);
printf("\r\nATT7022EU Adjusting Finished!\r\n");
//ATT_Test();
while(1) //每1秒钟读取一次ATT7022EU,更新显示一次
{
Read_ATT_AData(); //读取ATT7022EU的数据
Read_ATT_BData();
Read_ATT_CData();
Read_ATT_TData();
sprintf(AURms_chars,"%3.2f",(float)(ADataTypeDef.Rurms)); //float转char[]
sprintf(BURms_chars,"%3.2f",(float)(BDataTypeDef.Rurms));
sprintf(CURms_chars,"%3.2f",(float)(CDataTypeDef.Rurms));
sprintf(TURms_chars,"%3.2f",(float)(TDataTypeDef.Rurms));
sprintf(AIRms_chars,"%2.2f",(float)(ADataTypeDef.Rirms));
sprintf(BIRms_chars,"%2.2f",(float)(BDataTypeDef.Rirms));
sprintf(CIRms_chars,"%2.2f",(float)(CDataTypeDef.Rirms));
sprintf(TIRms_chars,"%2.2f",(float)(TDataTypeDef.Rirms));
sprintf(Freq_chars,"%2.2f",(float)(TDataTypeDef.Rfreq));
TEXT_SetText(hTextelse[10],AURms_chars); //显示从ATT7022读取到的值,为什么读不到数值?(10次能读取到1次,显示各相电压为250多V,频率为50Hz)
TEXT_SetText(hTextelse[11],BURms_chars); //显示从ATT7022读取到的值,为什么读不到数值?(10次能读取到1次,显示各相电压为250多V,频率为50Hz)
TEXT_SetText(hTextelse[12],CURms_chars); //显示从ATT7022读取到的值,为什么读不到数值?(10次能读取到1次,显示各相电压为250多V,频率为50Hz)
TEXT_SetText(hTextelse[13],TURms_chars); //显示从ATT7022读取到的值,为什么读不到数值?(10次能读取到1次,显示各相电压为250多V,频率为50Hz)
TEXT_SetText(hTextelse[17],AIRms_chars); //显示从ATT7022读取到的值,为什么读不到数值?(10次能读取到1次,显示各相电压为250多V,频率为50Hz)
TEXT_SetText(hTextelse[18],BIRms_chars); //显示从ATT7022读取到的值,为什么读不到数值?(10次能读取到1次,显示各相电压为250多V,频率为50Hz)
TEXT_SetText(hTextelse[19],CIRms_chars); //显示从ATT7022读取到的值,为什么读不到数值?(10次能读取到1次,显示各相电压为250多V,频率为50Hz)
TEXT_SetText(hTextelse[20],TIRms_chars); //显示从ATT7022读取到的值,为什么读不到数值?(10次能读取到1次,显示各相电压为250多V,频率为50Hz)
TEXT_SetText(hTextelse[22],Freq_chars); //显示从ATT7022读取到的值,为什么读不到数值?(10次能读取到1次,显示各相电压为250多V,频率为50Hz)
//根据从ATT7022读取到的值做出判断
if(((float)(ADataTypeDef.Rurms) > 100.00) && ((float)(BDataTypeDef.Rurms) > 100.00) && ((float)(CDataTypeDef.Rurms) > 100.00) )
{
......//省略了无关代码
}
OSTimeDlyHMSM(0,0,1,0); //每1秒钟刷新一次
}
}
void Output_ATT(DataTypeDef output)
{
printf("\r\n********************\r\n");
// // printf("\r\nP = %x !\r\n",output.P);
// // printf("\r\n %f !\r\n",output.Rp);
// // printf("\r\nQ = %x !\r\n",output.Q);
// // printf("\r\n %f !\r\n",output.Rq);
// // printf("\r\nS = %x !\r\n",output.S);
// // printf("\r\n %f !\r\n",output.Rs);
printf("\r\nURms = %x !\r\n",output.URms);
printf("\r\n %f !\r\n",output.Rurms);
printf("\r\nIRms = %x !\r\n",output.IRms);
printf("\r\n %f !\r\n",output.Rirms);
// // printf("\r\nPf = %x !\r\n",output.Pf);
// // printf("\r\n %f !\r\n",output.Rpf);
printf("\r\nFreq = %x !\r\n",output.Freq);
printf("\r\n %f !\r\n",output.Rfreq);
printf("\r\n********************\r\n");
}
void delay_us1(u16 time) //这个延时函数没问题吧?
{
u16 i=0;
while(time--)
{
i=10; //自己定义
while(i--);
}
}
串口调试助手显示如下:
第1次:
Initializing ATT7022EU...
ATT7022EU initializing Finished!
Adjusting ATT7022EU...
In 0xC6 with 0x5A: 0x00 is 5555 ! //为什么读到的值是错误的?
It should be 0x00AAAA !
ModeCfg is 7c02 ! //为什么读到的值是错误的?
It should be 0xB9FE !
EMUCfg is f804 ! //为什么这个值读取正确?
It should be 0xF804 !
ModuleCfg is 0 ! //为什么读到的值是错误的?
It should be 0x3437 !
In 0xC6 without 0x5A: 0x00 is aaaa ! //为什么读到的值是错误的?
We are using ATT7022EU, so it should be 0x7122A0/0x705200 !
ATT7022EU Adjusting Finished!
------------------------------------------------------------
第2次:
Initializing ATT7022EU...
ATT7022EU initializing Finished!
Adjusting ATT7022EU...
In 0xC6 with 0x5A: 0x00 is aaaa ! //为什么上一次读取错误,这次读到的值又是正确的?
It should be 0x00AAAA !
ModeCfg is 89aa ! //为什么读到的值是错误的?
It should be 0xB9FE !
EMUCfg is f804 ! //为什么这个值读取正确?
It should be 0xF804 !
ModuleCfg is 3527 ! //为什么读到的值是错误的?
It should be 0x3437 !
In 0xC6 without 0x5A: 0x00 is 7122a0 ! //为什么上一次读取错误,这次读到的值又是正确的?
We are using ATT7022EU, so it should be 0x7122A0/0x705200 !
ATT7022EU Adjusting Finished!
|