我用STM32外接ADC转换模块采集2个通道的模拟电压,转换成数字电压,通过计算Nor=(v1-v2)/(V1+V2),计算结果在液晶LCD12864显示 其中V1, v2都是采样一千次后的平均值。V1 和V2能立马显示,但是计算出的Nor不能立马在在LCd显示,但是按一下复位键立马就显示出来了。
主要函数如下:
int main(void)
{
float voltage=0;
float voltage2=0;
int vol_int1=0;
int vol_int2=0;
int i=0;
float sun1=0,sun2=0,n=0;
//out1=26214;
AD_config();
AD_INT();
LED_config();
INIT_PORT();
lcd_clear();
clrRAM_12864();
lcd_string(0,0,"vol1"); //ÖÐÎÄÒ²¿ÉÒÔ
lcd_string(1,3,"V");
lcd_string(2,0,"vol2"); //ÖÐÎÄÒ²¿ÉÒÔ
lcd_string(3,3,"V");
lcd_string (0,4,"Nor");
while(1)
{
sum1=0,av1=0,sum2=0,av2=0;
/***************¹éÒ»Öµ****************/
if(sun1+sun2!=0)
{
if(sun1>=sun2)
{
n =(sun1-sun2)/(sun1+sun2);
nor=floatToint(n);
write_command(0x94);
write_Data(0x30);
write_Data('.');
write_Data(0x30+(nor/100));
write_Data(0x30+(nor%100/10));
write_Data(0x30+(nor%100%10));
}
else
{
n =(sun2-sun1)/(sun1+sun2);
nor=floatToint(n);
write_command(0x94);
write_Data('-');
write_Data(0x30);
write_Data('.');
write_Data(0x30+(nor/100));
write_Data(0x30+(nor%100/10));
write_Data(0x30+(nor%100%10));
}
}
/***************ͨµÀ1*****************/
for(i=0;i<1000;i++)
{
ch_sel_1();
read_spi();
out1=dateout;
voltage=(float)(out1)*5/16384; //×&ordf;&raquo;&raquo;&sup3;&Eacute;&micro;&ccedil;&Ntilde;&sup1;&Ouml;&micro; &ETH;&iexcl;&Ecirc;&yacute;
vol_int1=floatToint(voltage); //±&pound;&Aacute;&ocirc;&Egrave;&yacute;&Icirc;&raquo;&ETH;&iexcl;&Ecirc;&yacute;
sum1=sum1+vol_int1;
sun1=sun1+voltage;
ch_sel_2();
read_spi();
out2=dateout;
voltage2=(float)(out2)*5/16384; //×&ordf;&raquo;&raquo;&sup3;&Eacute;&micro;&ccedil;&Ntilde;&sup1;&Ouml;&micro; &ETH;&iexcl;&Ecirc;&yacute;
vol_int2=floatToint(voltage2); //±&pound;&Aacute;&ocirc;&Egrave;&yacute;&Icirc;&raquo;&ETH;&iexcl;&Ecirc;&yacute;
sum2=sum2+vol_int2;
sun2=sun2+voltage2;
}
av1=sum1/1000;
write_command(0x90);
write_Data(0x30+av1/1000);
write_Data('.');
write_Data(0x30+av1%1000/100);
write_Data(0x30+av1%1000%100/10);
write_Data(0x30+av1%1000%100%10);
/***************&Iacute;¨&micro;&Agrave;2****************/
av2=sum2/1000;
write_command(0x98);
write_Data(0x30+av2/1000);
write_Data('.');
write_Data(0x30+av2%1000/100);
write_Data(0x30+av2%1000%100/10);
write_Data(0x30+av2%1000%100%10);
}
}
求各位大神帮帮我 看看原因 |