void EXTI15_10_IRQHandler(void)
{
//先开始初始化IO口
RCC->APB2ENR|=1<<2; //PA时钟使能
RCC->APB2ENR|=1<<0; //开启辅助时钟
RCC->APB2ENR&=~(1<<12); //SPI1时钟失能
GPIOA->CRL&=0X0F00FFFF;//PA457
GPIOA->CRL|=0X30330000;//
GPIOA->CRL&=0XF0FFFFFF;//PA6
GPIOA->CRL|=0X08000000;//
GPIOA->ODR|=0XF0;
//中断处理
Convert_Pos();
printf("x is %d",Pen_Point.X0);
printf("y is %d",Pen_Point.Y0);
if(Pen_Point.X0>=70-16&& en_Point.X0<=70+16&& en_Point.Y0>=270-16&& en_Point.Y0<=270+16)flag='L';
if(Pen_Point.X0>=120-16&& en_Point.X0<=120+16&& en_Point.Y0>=270-16&& en_Point.Y0<=270+16)flag='P';
if(Pen_Point.X0>=170-16&& en_Point.X0<=170+16&& en_Point.Y0>=270-16&& en_Point.Y0<=270+16)flag='R';
if(Pen_Point.X0>=20-10&& en_Point.X0<=20+10&&Pen_Point.Y0>=40-10&&Pen_Point.Y0<=40+10)flag='+';
if(Pen_Point.X0>=20-10&&Pen_Point.X0<=20+10&&Pen_Point.Y0>=85-10&&Pen_Point.Y0<=85+10)flag='-';
delay_ms(400); //相当于消钭
//恢复端口设置
RCC->APB2ENR|=1<<2; //PORTA时钟使能
RCC->APB2ENR|=1<<12; //SPI1时钟使能
GPIOA->CRL&=0X000FFFFF;
GPIOA->CRL|=0XBBB00000;//PA5.6.7复用
GPIOA->ODR|=0X7<<5; //PA5.6.7上拉
SPI1->CR1|=1<<6; //SPI设备使能
RCC->APB2ENR|=1<<3;//先使能外设IO PORTB时钟
GPIOB->CRL&=0X00FFFFFF;//PB6/7 推挽输出
GPIOB->CRL|=0X33000000;
GPIOB->ODR|=3<<6; //PB6,7 输出高
EXTI->PR=1<<13; //清除LINE1上的中断标志位
}
以上代码基本思路是:进入中断后,首先关闭spi(触摸屏占用spi口但不用spi通信,所以要先关闭,避免影响,然后在出中断前在使能spi),然后判断位置,根据不同位置
写不同的flag,出中断前使能spi。
现在问题是:触摸的时候经常会卡死,就是触摸要很有技术(一点就要放开就没事)
各位高手解答一下啊
在线等
|