void __irq ADC_ISR(void)
{
U32 saveAdcdly;
if(rADCDAT0&0x8000)//順序X 方向、Y 方向測量
{
rADCTSC&=0xff;// Set stylus down interrupt bit
}本文引用地址:http://m.butianyuan.cn/article/201611/322169.htmrADCTSC=(1<<3)|(1<<2);//Pull-up disable, Seq. X,Y postion measure.
saveAdcdly=rADCDLY;
rADCDLY=40000;//Normal conversion mode delay about (1/50M)*40000=0.8ms
rADCCON|=0x1;//start ADC
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);//讀取x坐標(biāo)數(shù)據(jù)
ydata=(rADCDAT1&0x3ff);//讀取y坐標(biāo)數(shù)據(jù)
//YH 0627, To check Stylus Up Interrupt.
rSUBSRCPND|=BIT_SUB_TC;//清除相應(yīng)的寄存器
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
{
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()//根據(jù)點擊的觸摸屏的位置來判斷控制哪一個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清零防止下次收到其他數(shù)據(jù)時干擾
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設(shè)置為輸出
rGPBDAT|=0x560;//4個LED全滅
Touch_Screen_Init();
while(1);
}
評論