while(rADCCON & 0x1); //check if Enable_start is low
while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high, This line is necessary~!!
while(!(rSRCPND & (BIT_ADC))); //check if ADC is finished with interrupt bit
xdata=(rADCDAT0&0x3ff);
ydata=(rADCDAT1&0x3ff);
//YH 0627, To check Stylus Up Interrupt.
rSUBSRCPND|=BIT_SUB_TC;
ClearPending(BIT_ADC);
rINTSUBMSK &=~(BIT_SUB_TC);
rINTMSK &=~(BIT_ADC);
rADCTSC =0xd3; //Waiting for interrupt
rADCTSC=rADCTSC|(1<<8); // Detect stylus up interrupt signal.
while(1) //to check Pen-up state
{
if(rSUBSRCPND & (BIT_SUB_TC)) //check if ADC is finished with interrupt bit
{
Uart_Printf("Stylus Up Interrupt~!\n");
break; //if Stylus is up(1) state
}
}
Uart_Printf("count=%d XP=%04d, YP=%04d\n", count++, xdata, ydata); //X-position Conversion data
rADCTSC =rADCTSC&~(1<<8); // Detect stylus Down interrupt signal.
rSUBSRCPND |=BIT_SUB_TC;
rINTSUBMSK &=~(BIT_SUB_TC); // Unmask sub interrupt (TC)
ClearPending(BIT_ADC);
}