代码拉取完成,页面将自动刷新
#include "stm32f0xx.h"
#include "LCD_PARALLEL_12864.h"
#include "init.h"
#define VOLTAGE_SCALE 3 //电压分压系数,原理图的R10*R11/R10
float g_volltage_adjust=-0.05f;
float g_current_adjust=-0.045f;
unsigned int RegularConvertedAdcValue[2];
unsigned int VOL_value[16];
unsigned int CUR_value[16];
unsigned long timecount;
unsigned long keycount;
unsigned char key_flag;
unsigned char adc_collect_flag;
unsigned char adc_calculate_ok;
unsigned int pwm_timer;
unsigned int pwm_bfb;
float g_current;
float g_volltage;
float g_power;
float g_capacity;
float mah_display;
void float_display( int x,int y ,float a )
{
unsigned long temp;
unsigned short i,j,k,l,m;
a*=1000;
(unsigned long)temp = a;
if( temp>10000000 )
{
temp/=1000;
i=((temp/10000)%10);
j=((temp/1000)%10);
k=(temp%1000)/100;
l=(temp%100)/10;
m=(temp%10);
Disp_Nub8X16( y,x,i,1 );
Disp_Nub8X16( y,x+8,j,1 );
Disp_Nub8X16( y,x+16,k,1 );
Disp_Nub8X16( y,x+24,l,1 );
Disp_Nub8X16( y,x+32,m,1 );
}
else if( temp >=1000000 )
{
temp/=1000;
i=temp/1000;
j=((temp/100)%10);
k=(temp%100)/10;
l=(temp%10);
Disp_Nub8X16( y,x+8,i,1 );
Disp_Nub8X16( y,x+16,j,1 );
Disp_Nub8X16( y,x+24,k,1 );
Disp_Nub8X16( y,x+32,l,1 );
}
else if( temp>=100000&&temp<1000000 )
{
temp/=100;
i=temp/1000;
j=((temp/100)%10);
k=(temp%100)/10;
l=(temp%10);
Disp_Nub8X16( y,x,i,1 );
Disp_Nub8X16( y,x+8,j,1 ); //小数点
Disp_Nub8X16( y,x+16,k,1 );
Disp_Nub8X16( y,x+24,10,1 );
Disp_Nub8X16( y,x+32,l,1 );
}
else if( temp>=10000&&temp<100000 )
{
temp/=10;
i=temp/1000;
j=((temp/100)%10);
k=(temp%100)/10;
l=(temp%10);
Disp_Nub8X16( y,x,i,1 );
Disp_Nub8X16( y,x+8,j,1 );
Disp_Nub8X16( y,x+16,10,1 );
Disp_Nub8X16( y,x+24,k,1 );
Disp_Nub8X16( y,x+32,l,1 );
}
else if( temp<10000 )
{
i=temp/1000;
j=((temp/100)%10);
k=(temp%100)/10;
l=(temp%10);
Disp_Nub8X16( y,x,i,1 );
Disp_Nub8X16( y,x+8,10,1 ); //小数点
Disp_Nub8X16( y,x+16,j,1 );
Disp_Nub8X16( y,x+24,k,1 );
Disp_Nub8X16( y,x+32,l,1 );
}
}
unsigned int value_avevage( unsigned int *a )
{
u8 i;
unsigned long j=0;
unsigned int k;
for( i=0;i<16;i++ )
{
j+=a[i];
}
j/=4;
k=j;
return k;
}
uint16_t ADC_Get_Result(uint32_t ch)
{
ADC_ChannelConfig(ADC1, ch, ADC_SampleTime_239_5Cycles);
ADC1->CHSELR = ch;
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY)){};
ADC_StartOfConversion(ADC1);
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET){};
return ADC_GetConversionValue(ADC1)&0x00000fff;
}
unsigned int vol_data;
unsigned int cur_data;
unsigned short xy=150;
uint16_t lll;
int main(void)
{
unsigned char i,j;
RCC_ClocksTypeDef ClockInfo;
for( i=0;i<50;i++ )
deviceinit();
DMA_Cmd(DMA1_Channel1, ENABLE);
timecount=1000;//开始采集
j=0;
while (1)
{
RCC_GetClocksFreq(&ClockInfo);
if( key_flag )
{
key_flag=0;
for( i=0;i<100;i++ );
if(!GPIO_ReadInputDataBit( GPIOB,GPIO_Pin_7 ))
{
j+=1,keycount=1;
}
}
if( adc_collect_flag )
{//adc16次采集完成
adc_collect_flag=0;
vol_data = value_avevage(VOL_value);
cur_data = value_avevage(CUR_value);
g_current=(float)cur_data;
//g_current=(g_current/4095)*0.825f;
g_volltage=(float)vol_data;
g_volltage=(g_volltage/4095)*0.825f;
g_volltage*=VOLTAGE_SCALE;
g_volltage+=g_volltage_adjust;
g_current-=48;
g_current=(g_current/348)*0.125f;
g_current+=g_current_adjust;
g_power=g_volltage*g_current;
adc_calculate_ok=1;
}
if(j>0&&keycount>1500)
{
keycount=0;
if(j==1)
{
pwm_bfb++;
if(pwm_bfb==5){pwm_bfb=0;}
}
if(j==3)
{
mah_display=0;
}
if(j==5)
{
g_volltage_adjust=5-g_volltage;
}
j=0;
}
if( adc_calculate_ok&&timecount>1000 )
{
adc_calculate_ok=0;
timecount=1;
g_capacity=g_power*4.5045f;
mah_display+=g_capacity;
g_capacity+=g_capacity;
float_display( 48,0,g_volltage );
float_display( 48,2,g_current );
float_display( 48,4,g_power );
float_display( 48,6,mah_display );
}
}
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。