LCD驱动、绘图与文字显示软件
void SCU_Refresh()
{
static u8 ntmp1=0;
static int tempstart = 0;
static int tempend = 0;
static int wavenum = 4;
static int jumpwave = 5;
static int nT = 2;
char * P_Char=&gstrltemp[0];
int i,j,k,l;
u16 x,y;
switch (SCUtype)
{
case MainScu2://Home 示波器界面
{
//底图
gDrawRectangle(WHITE,5,5,300,200,1);
// 仿真曲线
for(x=0;x<300;x++)
{
line1[x]=(u8)(50*sin(0.1*x+ntmp1)+100);
}
ntmp1+=2;
// 测量曲线
// AdcBuf
fMax=-80;
fMin=80;
for(x=0;x<300;x++)
{
ftmp2[x]=(AdcBuf[x]-2048)*Ka2V*Kbcbf[nSVinx]*Kopf[nSVinx]*2;
if(fMax<ftmp2[x])fMax=ftmp2[x];
if(fMin>ftmp2[x])fMin=ftmp2[x];
ftmp=ftmp2[x]*Kpsh;
if(ftmp>=98.00F)ftmp=98.0F;
else if(ftmp<=-98.00F)ftmp=-98.0F;
line1[x]=(u8)(ftmp+100+5);//0.04885197850512945774303859306302
if(micTTT) line1_f[x]= line1[x];
}
if(micTTT)
{
// memcpy(line1_,line1,300);
for(x=0;x<60;x++)
{
line1[x*5]=line1_f[x];
line1[x*5+1]=line1_f[x]+(u8)((line1_f[x+1]-line1_f[x])*0.2F);
line1[x*5+2]=line1_f[x]+(u8)((line1_f[x+1]-line1_f[x])*0.4F);
line1[x*5+3]=line1_f[x]+(u8)((line1_f[x+1]-line1_f[x])*0.6F);
line1[x*5+4]=line1_f[x]+(u8)((line1_f[x+1]-line1_f[x])*0.7F);
}
}
fVpp=(fMax-fMin);//Kopf[nSVinx]*
fAveV=(fMax+fMin)*0.5F;
// 频率计算
for(i=0;i<300;i++)
{
ftmp2[i]=ftmp2[i]-fAveV;
}
j=0;
tempend =tempstart=0;
for(i=0;i<299;i++)
{
if((ftmp2[i]<=0)&&(ftmp2[i+1]>=0)||(ftmp2[i]>=0)&&(ftmp2[i+1]<=0))
{
if (j == 0) tempstart = i;
else if (j == 1)
{
k = i - tempstart;
if (k > 150) break;
wavenum = 150 / k;
if (wavenum % 2 == 1) wavenum += 1;
if (k < 10)
{
tempend = 0;
break;
}
if (k < 20) jumpwave = k / 4;
}
j = j + 1;
if (j > wavenum)
{
tempend = i;
break;
}
i = i + jumpwave;
}
}
if (tempend - tempstart > 0)
{
CYcyc=cycyc[ideTimr];
cycle = ((tempend - tempstart) * CYcyc) * 2 / wavenum;//um 一共wavenum/2 个周期
freq = 1 / cycle;
}
else
{
cycle = -1;
freq = -1;
}
if(lineMod)
{
for(i=1;i<299;i++)
{
Gui_DrawLine(i+5,line1o[i],i+6,line1o[i+1]+3,BLACK);
}
memcpy(line1o,line1,300);
//绘制曲线
for(i=1;i<299;i++)
{
Gui_DrawLine(i+5,line1o[i],i+6,line1o[i+1]+3,GREEN);
}
}
else
{
for(i=1;i<299;i++)
{
LCD_Fast_DrawPoint(i+5,line1o[i]+6,BLACK);
// y=
// gDrawLine
}
memcpy(line1o,line1,300);
//绘制曲线
for(i=1;i<299;i++)
{
LCD_Fast_DrawPoint(i+5,line1[i]+6,GREEN);
// y=
// gDrawLine
}
}
gDrawLeVeLine(DGRAY,155,5,155,205,1);
gDrawLeVeLine(DGRAY,5,103,305,103,1);
for(i=0;i<4;i++)
{
for(j=0;j<6;j++)
{
if(i<2)
{
x=155-(i+1)*50;
if(j<3)
{
y=105-(j+1)*25;
}
else
{
y=105+(j-2)*25;
}
}
else
{
x=155+(i-1)*50;
if(j<3)
{
y=105-(j+1)*25;
}
else
{
y=105+(j-2)*25;
}
}
LCD_Fast_DrawPoint(x,y,LGRAY);
}
}
if(micTTT)
gDrawString(BLUE,0,0,210,40,16,16," 20us");
else
gDrawString(BLUE,0,0,210,40,16,16,strts[ideTimr]);
// strV u8 nSVinx=0;
gDrawString(MAGENTA,0,45,210,40,16,16,strV[nSVinx]);
gDrawString(LGRAY,0,95,210,24,12,12,"Vpp:");
sprintf(P_Char,"% 6.2fV",fVpp);
gDrawString(BLUE,0,120,210,56,16,16,P_Char);
if(freq<0.0001F)
{
gDrawString(MAGENTA,0,180,210,64,16,16," ---.-Hz");
gDrawString(BLUE,0,245,210,64,16,16," ---.-ms");
}
else if(freq<1000)
{
sprintf(P_Char,"% 6.2fHz",freq);
gDrawString(MAGENTA,0,180,210,64,16,16,P_Char);
sprintf(P_Char,"% 6.1fms",1000/freq);
gDrawString(BLUE,0,245,210,72,16,16,P_Char);
}
else
{
freq=freq*0.001F;
sprintf(P_Char,"% 6.2fKHz",freq);
gDrawString(MAGENTA,0,180,210,64,16,16,P_Char);
sprintf(P_Char,"% 6.0fus",1000/freq);
gDrawString(BLUE,0,245,210,72,16,16,P_Char);
}
}
break;
default:
SCUtype=MainScu;
break;
}
} |