/*===================================================================
// function: read touch data
// in: void
// retun: void
// date: 2005/8/10
===================================================================*/
void keydown(void)
{
unsigned char tmp; // temporary data
smalldelay(20); // delay wait tranquilization
startspi(); // begin data transfer
smalldelay(1);
sendspi(0x90); // difference conversion, x data
smalldelay(2); // delay wait x conversion
sendspi(0x00);
tmp = readspi(); // first 7 bit x data
if(tmp == 0x7F) // error read
return;
positionx = tmp;
positionx <<= 5; // left shift 5 bit
sendspi(0xD0); // difference conversion, y data
tmp = readspi(); // last 5 bit x data
tmp >>= 3; // right shift 3 bit
positionx += tmp; // real x data
smalldelay(2); // delay wait y conversion
sendspi(0x00);
tmp = readspi(); // first 7 bit y data
positiony = tmp;
positiony <<= 5;
sendspi(0x00); // only for read last y data
tmp = readspi();
tmp >>= 3;
positiony += tmp; // real y data
endspi();
}