新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 四 ARM9(S3C2440)的ADC和觸摸屏控制——理論知識(shí)

四 ARM9(S3C2440)的ADC和觸摸屏控制——理論知識(shí)

作者: 時(shí)間:2016-11-27 來(lái)源:網(wǎng)絡(luò) 收藏


void __irq ADC_ISR(void)
{

U32 saveAdcdly;
if(rADCDAT0&0x8000)//順序X 方向、Y 方向測(cè)量
{
rADCTSC&=0xff;// Set stylus down interrupt bit
}

本文引用地址:http://butianyuan.cn/article/201611/322169.htm

rADCTSC=(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ù)點(diǎn)擊的觸摸屏的位置來(lái)判斷控制哪一個(gè)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ù)時(shí)干擾
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個(gè)LED全滅
Touch_Screen_Init();
while(1);
}


上一頁(yè) 1 2 下一頁(yè)

關(guān)鍵詞: ARM9S3C2440ADC觸摸屏控

評(píng)論


技術(shù)專(zhuān)區(qū)

關(guān)閉