管理员
最后登录1970-1-1
在线时间 小时
注册时间2013-3-25
|
发表于 2013-11-2 17:44:54
|
显示全部楼层
使用条件编译(代码中红色部分),把原来的校正的代码屏蔽掉,把实测出的校正参数写到该函数中,
导致的结果是进不了中断,画不了。
int Touch_Calibrate(void)
{
#if 1
uint8_t i;
u16 test_x=0, test_y=0;
u16 gap_x=0, gap_y=0;
Coordinate * Ptr;
for(i=0; i<4; i++)
{
LCD_Clear(0, 0, 320, 240, BACKGROUND);
LCD_DispStr(110, 110, (uint8_t *)"Touch Calibrate......", RED);
LCD_DisNum(160, 90, i+1, RED);
/* 适当的延时很有必要 */
Delay_ms(500);
DrawCross(DisplaySample.x,DisplaySample.y); //显示校正用的“十”字
do
{
Ptr=Read_2046_2(); //读取TSC2046数据到变量ptr
}
while( Ptr == (void*)0 ); //当ptr为空时表示没有触点被按下
ScreenSample.x= Ptr->x; //把读取的原始数据存放到全局变量ScreenSample结构体
ScreenSample.y= Ptr->y;
}
/* 用原始参数计算出 原始参数与坐标的转换系数。 */
Cal_touch_para( &DisplaySample[0],&ScreenSample[0],&touch_para ) ;
/*取一个点计算X值*/
test_x = ( (touch_para.An * ScreenSample[3].x) +
(touch_para.Bn * ScreenSample[3].y) +
touch_para.Cn
) / touch_para.Divider ;
/*取一个点计算Y值*/
test_y = ( (touch_para.Dn * ScreenSample[3].x) +
(touch_para.En * ScreenSample[3].y) +
touch_para.Fn
) / touch_para.Divider ;
/* 实际坐标与计算坐标的差 */
gap_x = (test_x > DisplaySample[3].x)?(test_x - DisplaySample[3].x)DisplaySample[3].x - test_x);
gap_x = (test_y > DisplaySample[3].y)?(test_y - DisplaySample[3].y)DisplaySample[3].y - test_y);
//LCD_Rectangle(0,0,320,240,CAL_BACKGROUND_COLOR);
LCD_Clear(0, 0, 320, 240, BACKGROUND);
/* 可以通过修改这两个值的大小来调整精度 */
if((gap_x>10)||(gap_y>10))
{
LCD_DispStr(100, 100, (uint8_t *)"Calibrate fail", RED);
LCD_DispStr(100, 120, (uint8_t *)"try again", RED);
Delay_ms(2000);
return 1;
}
/* 校正系数为全局变量 */
aa1 = (touch_para.An*1.0)/touch_para.Divider;
bb1 = (touch_para.Bn*1.0)/touch_para.Divider;
cc1 = (touch_para.Cn*1.0)/touch_para.Divider;
aa2 = (touch_para.Dn*1.0)/touch_para.Divider;
bb2 = (touch_para.En*1.0)/touch_para.Divider;
cc2 = (touch_para.Fn*1.0)/touch_para.Divider;
#elif 0
aa1=0.088370;
bb1=-0.000468;
cc1=-24.042172;
aa2=0.0001891;
bb2=0.062395;
cc2=-10.223455;
LCD_DispStr(100, 100, (uint8_t *)"Calibrate Succed", RED);
Delay_ms(1000);
#endif
return 0;
}
|
|