while(1)//to check Pen-up state
{
if(rSUBSRCPND & (BIT_SUB_TC))//check if ADC is finished with interrupt bit
{
break;//if Stylus is up(1) state
}
}
ledcontrol();
rADCDLY=saveAdcdly;
rADCTSC=rADCTSC&~(1<8); // Detect stylus Down interrupt signal.
rSUBSRCPND|=BIT_SUB_TC;
rINTSUBMSK=~(BIT_SUB_TC);// Unmask sub interrupt (TC)
ClearPending(BIT_ADC);
}
void ledcontrol()//根据点击的触摸屏的位置来判断控制哪一个led的亮灭
{
if((xdata>100)&&(xdata<500)&&(ydata>500)&&(ydata<900))
{
key=1;
}
else if((xdata>500)&&(xdata<900)&&(ydata>500)&&(ydata<900))
{
key=2;
}
else if((xdata>100)&&(xdata<500)&&(ydata>100)&&(ydata<500))
{
key=3;
}
else if((xdata>500)&&(xdata<900)&&(ydata>100)&&(ydata<500))
{
key=4;
}
switch(key){
case 1:
rGPBDAT^=(1<5);
key=0;//将i清零防止下次收到其他数据时干扰
break;
case 2:
rGPBDAT^=(1<6);
key=0;
break;
case 3:
rGPBDAT^=(1<8);
key=0;
break;
case 4:
rGPBDAT^=(1<10);
key=0;
break;
default:break;
}
}
void Touchmain(void)
{
rGPBCON = 0x1dd7fc;// GPB5,GPB6,GPB8,GPB10设置为输出
rGPBDAT|=0x560;//4个LED全灭
Touch_Screen_Init();
while(1);
}