微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32f103的电阻触摸屏的五点校正算法

STM32f103的电阻触摸屏的五点校正算法

时间:09-25 来源:互联网 点击:

Cmd = DISABLE;

EXTI_Init(&EXTI_InitStructure);

//显示停止刷屏

TIM_Cmd(TIM3, DISABLE); //使能TIMx外设

LCD_Clear(White );

LCD_printString(110,20, "Adjustd Begin" ,Black);

delay_ms(5000);

// 定第一个点

LCD_Draw_Target(20, 20, Red);

while( GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_7));

while( (1-GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_7)))

{

x[0] = Read_XY(CMD_RDX);

y[0] = Read_XY(CMD_RDY);

LCD_ShowNum(150,80,x[0],Black);

LCD_ShowNum(150,110,y[0],Black);

delay_ms(200);

LCD_Color_Fill(150,80,200,120, White);

}

// 定第二个点

LCD_Draw_Target(300, 20, Red);

LCD_Draw_Target(20, 20, White);

while( GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_7));

while( (1-GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_7)))

{

x[1] = Read_XY(CMD_RDX);

y[1] = Read_XY(CMD_RDY);

LCD_ShowNum(150,80,x[1],Black);

LCD_ShowNum(150,110,y[1],Black);

delay_ms(200);

LCD_Color_Fill(150,80,200,120, White);

}

if(abs(y[1]-y[0]) >60)

{

LCD_Clear(White );

LCD_printString(110,20, "Adjustd Fail" ,Black);

delay_ms(5000);

LCD_Clear(White );

return 1;

}

// 定第三个点

LCD_Draw_Target(20, 220, Red);

LCD_Draw_Target(300, 20, White);

while( GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_7));

while( (1-GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_7)))

{

x[2] = Read_XY(CMD_RDX);

y[2] = Read_XY(CMD_RDY);

LCD_ShowNum(150,80,x[2],Black);

LCD_ShowNum(150,110,y[2],Black);

delay_ms(200);

LCD_Color_Fill(150,80,200,120, White);

}

if(abs(x[2]-x[0]) >80)

{

LCD_Clear(White );

LCD_printString(110,20, "Adjustd Fail" ,Black);

delay_ms(5000);

LCD_Clear(White );

return 1;

}

// 定第四个点

LCD_Draw_Target(300, 220, Red);

LCD_Draw_Target(20, 220, White);

while( GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_7));

while( (1-GPIO_ReadInputD

while( (1-GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_7)))

{

x[3] = Read_XY(CMD_RDX);

y[3] = Read_XY(CMD_RDY);

LCD_ShowNum(150,80,x[3],Black);

LCD_ShowNum(150,110,y[3],Black);

delay_ms(200);

LCD_Color_Fill(150,80,200,120, White);

}

if((abs(y[2]-y[3]) >60) || (abs(x[1]-x[3]) >80))

{

LCD_Clear(White );

LCD_printString(110,20, "Adjustd Fail" ,Black);

delay_ms(5000);

LCD_Clear(White );

return 1;

}

// 定第五个点

LCD_Draw_Target(160, 120, Red);

LCD_Draw_Target(300, 220, White);

while( GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_7));

while( (1-GPIO_ReadInputDataBit(GPIOG,GPIO_Pin_7)))

{

x[4] = Read_XY(CMD_RDX);

y[4] = Read_XY(CMD_RDY);

delay_ms(200);

}

//计算校正系数

// KX = ((abs(y[0]-y[2])/280+abs(y[1]-y[3])/280)/2);

// KY = ((abs(x[0]-x[1])/200+abs(x[2]-x[3])/200)/2);

KX = (((float)(y[0]-y[2])/280+(float)(y[1]-y[3])/280)/2);

KY = (((float)(x[0]-x[1])/200+(float)(x[2]-x[3])/200)/2);

XC = 160;

YC = 120;

XLC = y[4];

YLC = x[4];

// 定点完成

LCD_Clear(White );

LCD_printString(110,20, "Adjustd Done" ,Black);

delay_ms(5000);

LCD_Color_Fill(110,20,200,35, White);

LCD_printString(110,20, "Testing" ,Black);

EXTI_InitStructure.EXTI_Line = EXTI_Line7;

EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //为中断请求

EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//Falling下降沿 Rising上升

EXTI_InitStructure.EXTI_LineCmd = ENABLE;

EXTI_Init(&EXTI_InitStructure);

EXT

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top