新闻中心

EEPW首页>嵌入式系统>设计应用> 四 ARM9(S3C2440)的ADC和触摸屏控制——理论知识

四 ARM9(S3C2440)的ADC和触摸屏控制——理论知识

作者: 时间:2016-11-27 来源:网络 收藏


void __irq ADC_ISR(void)
{

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

本文引用地址://m.amcfsurvey.com/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坐标数据
ydata=(rADCDAT1&0x3ff);//读取y坐标数据

//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
{
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);
}


上一页 1 2 下一页

评论


技术专区

关闭