这里的
stop/run键,
store键 ,
call_out键 是画在触摸屏上的按键
void Display_Wave(void)
{
int j;
float store_buf[200];
float voltage; //计算电压
float max=0,min=4096,vpp=0; //最大值
int a,b; //显示最大值和最小值的整数部分和小数部分
Display_Table();
if(flag) //adc采满200个样本后就会置flag为1
{
while(!stop_run)
{
tp_dev.scan(0);
if((tp_dev.sta &0XC0) ==TP_CATH_PRES)
{
tp_dev.sta &=~(1<<6); //清除标志
if(tp_dev.x>210 && tp_dev.x<280) //按下stop/run键
{
if(tp_dev.y>165 && tp_dev.y<195)
stop_run=!stop_run;
}
if(tp_dev.y>165&&tp_dev.y<195)
{
if(tp_dev.x>155&&tp_dev.x<195) //按下store键
STMFLASH_Write(FLASH_SAVE_ADDR,(u16*)adc_buf,sizeof(adc_buf)); //这里的adc_buf是ad采集回来的值,在外部文件中,数据类型是也是float型
}
if(tp_dev.x>210 && tp_dev.x<280)
{
if(tp_dev.y>205 && tp_dev.y<235) //按下call_out键
{
POINT_COLOR=WHITE;
for(j=0;j<199;j++) //清除原有波形
{
LCD_DrawLine(j,(int)(adc_buf[j]),j+1,(int)(adc_buf[j+1]));
}
Display_Table(); //画表格
STMFLASH_Read(FLASH_SAVE_ADDR,(u16*)store_buf,sizeof(store_buf)); //把波形的数据提取出来.就是执行这一步之后,退出这个while循环,程序执行这个函数执行完就会死在HardFault_Handler\中,FLASH_SAVE_ADDR的值为0X08070000。调试了好久,也不知道问题出在了哪里。但是如果只是按下store键,然后退出这循环,程序还是可以正常执行的。就是按下call_out键之后就出了那种问题
POINT_COLOR=RED;
for(j=0;j<199;j++)
{
LCD_DrawLine(j,(int)(store_buf[j]),j+1,(int)(store_buf[j+1]));
adc_buf[j]=store_buf[j];
}
adc_buf[199]=store_buf[199];
}
}
}
}
POINT_COLOR=WHITE;
for(j=0;j<199;j++)
{
LCD_DrawLine(j,(int)(adc_buf[j]),j+1,(int)(adc_buf[j+1]));
}
POINT_COLOR=RED;
for(j=0;j<199;j++)
{
adc_buf[j]=(80-(float)buf[j]*(3.3*DIV/4096));
if(adc_buf[j]<0) adc_buf[j]=0; //边界检测
if(adc_buf[j]>160) adc_buf[j]=160;
if(max<(80-adc_buf[j])/DIV) //比较最大值最小值
max=(80-adc_buf[j])/DIV;
if(min>(80-adc_buf[j])/DIV)
min=(80-adc_buf[j])/DIV;
adc_buf[j+1]=(80-(float)buf[j+1]*(3.3*DIV/4096));
if(adc_buf[j+1]<0) adc_buf[j+1]=0; //边界检测
if(adc_buf[j+1]>160) adc_buf[j+1]=160;
LCD_DrawLine(j,(int)(adc_buf[j]),j+1,(int)(adc_buf[j+1]));
}
a=(int)max; //显示最大值
LCD_ShowxNum(250,55,a,1,16,0);
b=(int)((max-a)*10);
LCD_ShowxNum(266,55,b,1,16,0);
b=(int)((max-a)*100);
b%=10;
LCD_ShowxNum(274,55,b,1,16,0);
b=(int)((max-a)*1000);
b%=10;
LCD_ShowxNum(282,55,b,1,16,0);
a=(int)min; //显示最小值
LCD_ShowxNum(250,95,a,1,16,0);
b=(int)((min-a)*10);
LCD_ShowxNum(266,95,b,1,16,0);
b=(int)((min-a)*100);
b%=10;
LCD_ShowxNum(274,95,b,1,16,0);
b=(int)((min-a)*1000);
b%=10;
LCD_ShowxNum(282,95,b,1,16,0);
vpp=max-min;
a=(int)vpp; //显示峰峰值
LCD_ShowxNum(242,135,a,1,16,0);
b=(int)((vpp-a)*10);
LCD_ShowxNum(258,135,b,1,16,0);
b=(int)((vpp-a)*100);
b%=10;
LCD_ShowxNum(266,135,b,1,16,0);
b=(int)((vpp-a)*1000);
b%=10;
LCD_ShowxNum(274,135,b,1,16,0);
delay_ms(400);
TIM5->CR1|=0X01; //开启定时器5
TIM5->DIER|=1<<0; //允许更新中断
TIM5->DIER|=1<<1; //允许捕获中断
flag=0;
}
} |