初级会员

- 积分
- 85
- 金钱
- 85
- 注册时间
- 2012-6-13
- 在线时间
- 0 小时
|
这是触摸屏进行屏幕校准的,我设定三个点进行校准,屏幕每按一下,adjust_flag+1,记录相应的点的坐标
//产生中断
u16 adjust_flag=0;
void EXTI1_IRQHandler()
{
touch_sc=1;//触摸屏被按下
if(key_flag==1)
{
adjust_flag=adjust_flag+1;//设定断点
if(adjust_flag==4)
adjust_flag=0;
EXTI-> R=1<<1; //清除LINE1上的中断标志位
}
EXTI-> R=1<<1; //清除LINE1上的中断标志位
}
下面这段是 adjust_flag+1后所要执行的程序
void lcd_adjust()
{
u16 buf_temp[4][2];
Draw_Circle(10,10,6,BLACK);
LCD_DrawbigPoint(10,10,BLACK);
LCD_ShowString(18,10,"Touch First",BLACK);
Draw_Circle(230,10,6,BLACK);
LCD_DrawbigPoint(230,10,BLACK);
LCD_ShowString(130,10,"Touch Second",BLACK);
Draw_Circle(10,310,6,BLACK);
LCD_DrawbigPoint(10,310,BLACK);
LCD_ShowString(18,300,"Touch Third",BLACK);
if((touch_sc==1)&&(adjust_flag==1))//touch first
{ pen_int(0);
read_xy_twice();
buf_temp[0][0]=read_x;
buf_temp[0][1]=read_y;
pen_int(1);
}
if((touch_sc==1)&&(adjust_flag==2))//touch second
{ pen_int(0);
read_xy_twice();
buf_temp[1][0]=read_x;
buf_temp[1][1]=read_y;
pen_int(1);
}
if((touch_sc==1)&&(adjust_flag==3))//touch third
{
pen_int(0);
read_xy_twice();
buf_temp[2][0]=read_x;
buf_temp[2][1]=read_y;
x_shi=(float)(230-10)/(buf_temp[1][0]-buf_temp[0][0]);//得到x_shi
x_ge=((230+10)-x_shi*(buf_temp[1][0]+buf_temp[0][0]))/2;//得到x_shi
y_shi=(float)(310-10)/(buf_temp[2][1]-buf_temp[0][1]);//得到y_shi
y_ge=((310+10)-y_shi*(buf_temp[2][1]+buf_temp[0][1]))/2;//得到x_shi
key_flag=0;
LCD_clear(YELLOW);
pen_int(1);
}
}
问题是我无法保证每次按下adjust_flag都会加1,我只有在程序所示红色部分加断点,然后每次执行会加1,这是为什么?有做过的同学多提意见 |
|