int main(void)
{
u8 i;
u8 j;
u8 k;
u8 a;
float sub,sub1,sub2;
float temp0,temp[2],PIDOutput;
float PID0[]={2.5,2.6,3.8,1.1,1.3,0.8},PID[6];
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
delay_init(); //初始化延时函数
uart_init(115200); //初始化串口波特率为115200
LED_Init(); //初始化LED
LCD_Init(); //初始化LCD接口
Adc_Init(); //初始化ADC
Dac1_Init();
// KEY_Init(); //按键初始化
tp_dev.init(); //触摸屏初始化
POINT_COLOR=BLACK;//设置字体为红 {MOD}
//My_USART3_Init();//调用USARE3初始化函数进行USARE3初始化
/*
* 画实心圆
*/
//x0,y0:坐标
//r:半径
//color:颜 {MOD}
//===========画框
LCD_DrawRectangle(60, 105, 400, 145); //画矩形
LCD_DrawRectangle(60, 145, 400, 265); //画矩形
POINT_COLOR=RED;//设置字体为红 {MOD}
LCD_DrawRectangle(60, 290, 400, 340); //画矩形
LCD_DrawRectangle(60, 340, 400, 390); //画矩形
LCD_DrawRectangle(60, 390, 400, 440); //画矩形
LCD_DrawRectangle(60, 440, 400, 490); //画矩形
POINT_COLOR=BROWN;//设置字体为棕 {MOD}
LCD_DrawRectangle(60, 540, 400, 590); //画矩形
LCD_DrawRectangle(60, 590, 400, 640); //画矩形
LCD_DrawRectangle(60, 640, 400, 690); //画矩形
LCD_DrawRectangle(60, 690, 400, 740); //画矩形
//========字符定位显示=======
POINT_COLOR=RED;//设置字体为棕 {MOD}
LCD_ShowString(30,50,400,24,24,"Frequency Stablization PID Control");
POINT_COLOR=BLUE;//设置字体为蓝 {MOD}
//LCD_ShowString(90,130,200,24,24,"ADC1_CH00_VAL:");
LCD_ShowString(100,155,200,24,24,"ADC1_CH00_VOL:0.000V"); //先在固定位置显示小数点
//LCD_ShowString(90,190,200,24,24,"ADC1_CH01_VAL:");
LCD_ShowString(100,195,200,24,24,"ADC1_CH01_VOL:0.000V"); //先在固定位置显示小数点
LCD_ShowString(65,230,300,24,24,"Relative transmittance:0.00");
LCD_ShowString(152,355,300,24,24,"P1: + . - ");
LCD_ShowString(152,405,300,24,24,"I1: + . - ");
LCD_ShowString(152,455,300,24,24,"D1: + . - ");
POINT_COLOR=BLACK;//设置字体为黑
LCD_ShowString(110,115,200,24,24,"Input monitoring");
LCD_ShowString(160,305,200,24,24,"Temp PID");
LCD_ShowString(160,555,200,24,24,"PZT PID");
POINT_COLOR=BLUE;//设置字体为黑
LCD_ShowString(152,605,300,24,24,"P2: + . - ");
LCD_ShowString(152,655,300,24,24,"I2: + . - ");
LCD_ShowString(152,705,300,24,24,"D2: + . - ");
POINT_COLOR=BLACK;//设置字体为棕 {MOD}
LCD_ShowString(210,760,300,24,24,"Designed by: Vicmyuan");
POINT_COLOR=BLUE;//设置字体为蓝 {MOD}
DAC_SetChannel1Data(DAC_Align_12b_R, 0);//初始值为0
DAC_SetChannel2Data(DAC_Align_12b_R, 0);//初始值为0
while (TIM_GetITStatus(TIM3, TIM_IT_CC1) != RESET)
{
//=======两路ADC采样========
ADC1ConvertedVoltage[0] = 0;
for(i=0;i<2;i++)
{
ADC1ConvertedVoltage[i] = 0;
for(j=0;j<10;j++)//每个通道采10组数据做平均
{
ADC1ConvertedVoltage[i]+= ADC1ConvertedValue[j][i];
};
ADC1ConvertedVoltage[i] = ADC1ConvertedVoltage[i]/10;
};
sub1=ADC1ConvertedVoltage[0];//通道1的数据赋给sub1
sub2=ADC1ConvertedVoltage[1];//通道2的数据赋给sub2
sub=sub1/sub2;//通道1数据除以通道2的数据
//=======串口将两路比值(相对透过率)发送给上位机=======
printf("%f
",sub);
pid.ActualRt=sub;
//===========柱状图显示实时比值=========
temp0=sub;
if(temp0>1)
{temp0=1;}
LCD_Fill(15, 780-680*temp0, 23, 780, GREEN);
LCD_Fill(15, 100, 23, 780-680*temp0, RED);
//============显示比值数据==============
j=sub;
LCD_ShowxNum(340,230,j,1,24,0);
sub-=j;
sub*=100;
LCD_ShowxNum(363,230,sub,2,24,0X80);
//============显示两个AD通道电压值==============
for(k=0;k<2;k++)//显示两个通道的转换结果和电压
{
temp[k] = ADC1ConvertedVoltage[k]*3.3/4096;
i=temp[k]; //赋值整数部分给i变量,因为adcx为u16整形
LCD_ShowxNum(269,155+40*k,i,1,24,0); //显示电压值的整数部分,3.1111的话,这里就是显示3
temp[k]-=i; //把已经显示的整数部分去掉,留下小数部分,比如3.1111-3=0.1111
temp[k]*=1000; //小数部分乘以1000,例如:0.1111就转换为111.1,相当于保留三位小数。
LCD_ShowxNum(291,155+40*k,temp[k],3,24,0X80); //显示小数部分(前面转换为了整形显示),这里显示的就是111.
};
//============触摸屏改变PID参数数值==============
for(i=0;i<6;i++)
{
PID[i]=PID0[i];
}
if(tp_dev.touchtype&0X80)
{
ctp_test1(PID0, PID);
for(i=0;i<6;i++)
{
PID0[i]=PID[i];
}
}
for(i=0;i<3;i++)//显示Temp PID参数
{
a=PID[i];
LCD_ShowxNum(224,355+50*i,a,1,24,0);
PID[i]-=a;
PID[i]*=100;
LCD_ShowxNum(248,355+50*i,PID[i],2,24,0X80);
}
for(i=3;i<6;i++)//显示PZT PID参数
{
a=PID[i];
LCD_ShowxNum(224,455+50*i,a,1,24,0);
PID[i]-=a;
PID[i]*=100;
LCD_ShowxNum(248,455+50*i,PID[i],2,24,0X80);
}
pid.Kp=PID[0];
pid.Ki=PID[1];
pid.Kd=PID[2];
PIDOutput=PID_realize(0.5);
DAC_SetChannel1Data(DAC_Align_12b_R, PIDOutput);
pid.Kp=PID[3];
pid.Ki=PID[4];
pid.Kd=PID[5];
PIDOutput=PID_realize(0.5);
DAC_SetChannel2Data(DAC_Align_12b_R, PIDOutput);
delay_ms(1000);
// flag=0;
}
}
希望实现来一个下降沿while执行一次。现在的函数下载后屏幕更新一下就黑屏了。求助。
一周热门 更多>