|
我要在一个现成中驱动触屏,使用了
void rt_hw_touch_init(void)
{
RCC->APB2ENR |= 0X107C;
tp_GPIO_Config();//初始化触屏的管脚
TP_NVIC_Configuration();//初始化中断
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource6);//初始化PB.6触屏的INT脚,当按下触屏时会有下降沿
/* Configure Key Button EXTI Line to generate an interrupt on falling edge */
EXTI_InitStructure.EXTI_Line = EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
线程入口程序为char thread_touch_stack[512];
struct rt_thread thread_touch;
void rt_thread_entry_touch(void* parameter)
{
rt_hw_touch_init();
/* disable interrupt first */
while (1)
{
Touch_Adjust();
}
}
Touch_Adjust();这个程序时让程序一直检测是否在中断函数中设置的信号量变成低电平的,如果有下降沿,会进入程序,开始校正触屏
中断函数:
void EXTI9_5_IRQHandler(void)
{
rt_interrupt_enter();
if(EXTI_GetITStatus(EXTI_Line6) != RESET)
{
Pen_Point.Key_Sta=Key_Down;//按键按下 ,Pen_Point.Key_Sta为信号量,当有按下,会改变此值
EXTI_ClearITPendingBit(EXTI_Line6);
}
rt_interrupt_leave();
}
现在的问题是根本进不了EXTI9_5_IRQHandler(void)中断啊,我没有在其他函数中设置任何东西,而且在调用第一个现成的时候, CPSIE I ;PRIMASK=0, 开中断了,但是不管我把触屏程序放哪,始终进步了这个中断啊。十万火急啊,等着交东西,就差这个了,请求帮助,哪位大哥帮下忙啊!!!谢谢了
下面是校准程序,我不用实时系统的时候,是可以进的,现在只是会停在下面的while(1),这里
void Touch_Adjust(void)
{
u16 pos_temp[4][2];//坐标缓存值
u8 cnt=0;
u16 d1,d2;
u32 tem1,tem2;
float fac;
cnt=0;
POINT_COLOR=BLUE;
BACK_COLOR =WHITE;
LCD_Clear(WHITE);//清屏
POINT_COLOR=RED;//红色
LCD_Clear(WHITE);//清屏
Drow_Touch_Point(20,20);//画点1
Pen_Point.Key_Sta=Key_Up;//消除触发信号
Pen_Point.xfac=0;//xfac用来标记是否校准过,所以校准之前必须清掉!以免错误
while(1)
{
Pen_Point.Key_Sta=TFT_TP_INT;
if(Pen_Point.Key_Sta==Key_Down)//按键按下了
{
if(Read_TP_Once())//得到单次按键值
{
pos_temp[cnt][0]=Pen_Point.X;
pos_temp[cnt][1]=Pen_Point.Y;
cnt++;
Pen_Point.Key_Sta=Key_Up;
}
switch(cnt)
{
case 1:
LCD_Clear(WHITE);//清屏
Drow_Touch_Point(220,20);//画点2
break;
case 2:
LCD_Clear(WHITE);//清屏
Drow_Touch_Point(20,300);//画点3
break;
case 3:
LCD_Clear(WHITE);//清屏
Drow_Touch_Point(220,300);//画点4
break;
case 4: //全部四个点已经得到
//对边相等
tem1=abs(pos_temp[0][0]-pos_temp[1][0]);//x1-x2
tem2=abs(pos_temp[0][1]-pos_temp[1][1]);//y1-y2
tem1*=tem1;
tem2*=tem2;
d1=sqrt(tem1+tem2);//得到1,2的距离
tem1=abs(pos_temp[2][0]-pos_temp[3][0]);//x3-x4
tem2=abs(pos_temp[2][1]-pos_temp[3][1]);//y3-y4
tem1*=tem1;
tem2*=tem2;
d2=sqrt(tem1+tem2);//得到3,4的距离
fac=(float)d1/d2;
if(fac<0.95||fac>1.05||d1==0||d2==0)//不合格
{
cnt=0;
LCD_Clear(WHITE);//清屏
Drow_Touch_Point(20,20);
continue;
}
tem1=abs(pos_temp[0][0]-pos_temp[2][0]);//x1-x3
tem2=abs(pos_temp[0][1]-pos_temp[2][1]);//y1-y3
tem1*=tem1;
tem2*=tem2;
d1=sqrt(tem1+tem2);//得到1,3的距离
tem1=abs(pos_temp[1][0]-pos_temp[3][0]);//x2-x4
tem2=abs(pos_temp[1][1]-pos_temp[3][1]);//y2-y4
tem1*=tem1;
tem2*=tem2;
d2=sqrt(tem1+tem2);//得到2,4的距离
fac=(float)d1/d2;
if(fac<0.95||fac>1.05)//不合格
{
cnt=0;
LCD_Clear(WHITE);//清屏
Drow_Touch_Point(20,20);
continue;
}//正确了
//对角线相等
tem1=abs(pos_temp[1][0]-pos_temp[2][0]);//x1-x3
tem2=abs(pos_temp[1][1]-pos_temp[2][1]);//y1-y3
tem1*=tem1;
tem2*=tem2;
d1=sqrt(tem1+tem2);//得到1,4的距离
tem1=abs(pos_temp[0][0]-pos_temp[3][0]);//x2-x4
tem2=abs(pos_temp[0][1]-pos_temp[3][1]);//y2-y4
tem1*=tem1;
tem2*=tem2;
d2=sqrt(tem1+tem2);//得到2,3的距离
fac=(float)d1/d2;
if(fac<0.95||fac>1.05)//不合格
{
cnt=0;
LCD_Clear(WHITE);//清屏
Drow_Touch_Point(20,20);
continue;
}//正确了
//计算结果
Pen_Point.xfac=(float)200/(pos_temp[1][0]-pos_temp[0][0]);//得到xfac
Pen_Point.xoff=(240-Pen_Point.xfac*(pos_temp[1][0]+pos_temp[0][0]))/2;//得到xoff
Pen_Point.yfac=(float)280/(pos_temp[2][1]-pos_temp[0][1]);//得到yfac
Pen_Point.yoff=(320-Pen_Point.yfac*(pos_temp[2][1]+pos_temp[0][1]))/2;//得到yoff
POINT_COLOR=BLUE;
LCD_Clear(WHITE);//清屏
LCD_ShowString(35,110,"Touch Screen Adjust OK!");//校正完成
delay_ms(1000);
LCD_Clear(WHITE);//清屏
return;//校正完成
}
}
}
} |
|