1 The code:
void pro_keya_pix(unsigned short *pX, unsigned short *pY, unsigned char on)
{
unsigned char c;
unsigned short i, x = 0, y = 0;
SPI2CS_L;
c = 0xd0|on; // for Y
for(i=8; i>0; i–)
{
if (c&0x80) SPI2MO_H;
else SPI2MO_L;
c <<= 1;
SPI2SK_H;
SPI2SK_L;
}
SPI2MO_L;
for (i=32*25; i>0; i–) __NOP();
SPI2SK_H;
SPI2SK_L;
while (TPBSY_I) ;
for(i=12; i>0; i–)
{
y <<= 1;
SPI2SK_H;
y += SPI2MI_I;
SPI2SK_L;
}
for (i=32*5; i>0; i–) __NOP();
c = 0x90|on; // for X
for(i=8; i>0; i–)
{
if (c&0x80) SPI2MO_H;
else SPI2MO_L;
c <<= 1;
SPI2SK_H;
SPI2SK_L;
}
SPI2MO_L;
for (i=32*25; i>0; i–) __NOP();
SPI2SK_H;
SPI2SK_L;
while (TPBSY_I) ;
for(i=12; i>0; i–)
{
x <<= 1;
SPI2SK_H;
x += SPI2MI_I;
SPI2SK_L;
}
SPI2CS_H;
*pX = x;
*pY = y;
}
Note:32 NOP is1uS。
2: the bad x and y value:
LT: x=2451 / y=2421 (0X90/0Xd0)LC: x=2221 / y=1862 (0X90/0Xd0)LB: x=2226 / y=1310 (0X90/0Xd0) // T:上CT: x=1978 / y=1980 (0X90/0Xd0) // L:左CC: x=1974 / y=1872 (0X90/0Xd0) // B:下CB: x=1990 / y=1744 (0X90/0Xd0) // R:右
RT: x=1499 / y=1929 (0X90/0Xd0) // C:中
RC: x=1763 / y=1865 (0X90/0Xd0)
RB: x=1739 / y=1802 (0X90/0Xd0)
3. the X+ X- Y+ Y- wave is ok.
Can you give us any advice?
Thank you.