u16 TPReadX(void)
{
u16 x=0;
TP_CS();
SpiDelay(10);
//SPI_WriteByte(0xD0);
SPI_WriteByte(0xd0);
SpiDelay(20);
x=SPI_WriteByte(0x00);
x<<=8;
x+=SPI_WriteByte(0x00);
SpiDelay(20);
TP_DCS();
//x = 3671 - x;
x = x>>3;
return (x);
}
u16 TPReadY(void)
{
u16 y=0;
TP_CS();
SpiDelay(10);
//SPI_WriteByte(0x90);
SPI_WriteByte(0x90);
SpiDelay(20);
y=SPI_WriteByte(0x00);
y<<=8;
y+=SPI_WriteByte(0x00);
SpiDelay(20);
TP_DCS();
//y = 3601 - y;
y = y>>3;
return (y);
}
其中,关键位置在向SPI写数据的不同,如果你的触摸屏刚好反了,调换一下这两个就好了。
SPI_WriteByte(0x90);
SPI_WriteByte(0xd0);
另外,在GUI_TOUCH_X_TOUCH.C中,也要做相应的修改。
int GUI_TOUCH_X_MeasureY(void) {
unsigned char t=0,t1,count=0;
unsigned short int databuffer[10]={5,7,9,3,2,6,4,0,3,1};//数据组
unsigned short temp=0,Y=0;
while(count<10) //循环读数10次 //GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0)==0&&
{
databuffer[count]= 3671 + 273-TPReadY(); //
count++;
}
if(count==10)//一定要读到10次数据,否则丢弃
{
do//将数据X升序排列
{
t1=0;
for(t=0;t<count-1;t++)
{
if(databuffer[t]>databuffer[t+1])//升序排列
{
temp=databuffer[t+1];
databuffer[t+1]=databuffer[t];
databuffer[t]=temp;
t1=1;
}
}
}while(t1);
Y=(databuffer[3]+databuffer[4]+databuffer[5])/3;
// if(X<=3730&&Y<=3730) //个人的屏根据初始参数修改.
// {
// if(X>=330)X-=330;
// else X=0;
// if(Y>=420)Y-=420;
// else Y=0;
// drawbigpoint(240-X/14,320-Y/10);
// }
}
return(Y);
}