typedef union { unsigned int ival; unsigned char ucval[2]; } uisval; uisval tsx; //TOUCH SCREEN X uisval tsy; //TOUCH SCREEN Y uisval temp1; uisval temp2; //COUNTERS FOR HOW MANY TIMES X AND Y ARE READ char myvalue = 0x00; char myvalue1 = 0x00; //INTERRUPT WHEN PENIRQ GOES LOW ISR(INT4_vect) { int i; EIMSK = 0x00; tsx.ival = 0; tsy.ival = 0; temp1.ival = 0xFFFF; temp2.ival = 0; myvalue = 0; myvalue1 = 0; PORTB &= 0xFE; //Enable Touch Interface CS = LOW while(temp1.ival != temp2.ival) { temp2.ival = temp1.ival; //temp1.ucval[1] = spi_transfer(0xD0); // Write Command Measure X-Position temp1.ucval[1] = spi_transfer(0x00); // Read ADC data X-Position (7-bit byte High) data: 0ddddddd (bit) temp1.ucval[0] = spi_transfer(0xD0); // Read ADC data X-Position (7-bit byte High) data: 0ddddddd (bit) myvalue++; } tsx.ival = temp1.ival; temp1.ival = 0xFFFF; temp2.ival = 0; while(temp1.ival != temp2.ival) { temp2.ival = temp1.ival; //temp1.ucval[1] = spi_transfer(0x90); // Write Command Measure X-Position temp1.ucval[1] = spi_transfer(0x00); // Read ADC data y-Position (7-bit byte High) data: 0ddddddd (bit) temp1.ucval[0] = spi_transfer(0x90); // Read ADC data y-Position (7-bit byte High) data: 0ddddddd (bit) myvalue1++; } tsy.ival = temp1.ival; PORTB |= 0x01; // Disable Touch Interface CS = HIGH tsx.ival = tsx.ival/8; tsy.ival = tsy.ival/8; EIMSK = 0x10; }