ARM9(S3C2440) Touch Screen

2023-11-01 54浏览
百检网是一家专业的第三方检测平台,汇聚众多拥有权威资质的第三方检测机构为你提供一站式的检测服务,做检测就上百检网。百检网让检测从此检测,一份报告全国通用,专业值得信赖。

触摸屏工作原理

触摸屏分为:电阻式,电容式,声表面波式,红外线扫描式等类型,使用的*多的是4线电阻式的触摸屏。

触摸屏工作流程

(1)、设置触摸屏接口为等待中断模式,等待触摸屏被按下。

(2)、如果中断(INT_TC)发生,选择X,Y坐标转换模式(X/Y坐标分别转换模式,X/Y坐标自动转换模式),启动AD转换。

(3)、当AD转换完毕后,通过中断(INT_ADC),获取X/Y坐标,ADCDAT0 bit[9:0]-x坐标,ADCDAT1 bit[9:0]-Y坐标。

(4)、设置触摸屏接口为等待中断模式,等待触摸笔离开触摸屏。

(5)、返回步骤1,等待下次触摸笔被按下。

实验主要代码

main,c

/*主函数*/

int Main(void)

{

int Scom=0;

Set_Clk();

Uart_Init(0,115200);

Uart_Select(Scom);

Test_Touchpanel();

while(1);

return 0;

}

/*触摸屏初始化*/

void Test_Touchpanel(void)

{undefined

rADCDLY=50000; //Normal conversion mode delay about (1/3.6864M)*50000=13.56ms

/*设置AD转频率*/

preScaler = ADC_FREQ;

preScaler = 50000000/ADC_FREQ - 1; //PCLK=50M

rADCCON = (1<<14)|(preScaler<<6); //ADCPRS En,PRSCVL

/*设置触摸屏为等待中断模式,等待触摸笔被按下*/

rADCTSC=0xd3; //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En

/*clear irq*/

rSRCPND = 0x80000000;

rINTPND = 0x80000000;

ClearSubPending(BIT_SUB_TC); //子中断也要清除

pISR_ADC = (U32)AdcTsAuto;

/*enable INT_TC irq*/

rINTMSK = 0x7fffffff;

EnableSubIrq(BIT_SUB_TC);

}

/*************************************************

Function name: AdcTsAuto

Parameter : void

Description : 中断服务程序

Return : void

Argument : void

Autor & date : Daniel

**************************************************/

static void __irq AdcTsAuto(void)

{undefined

U32 saveAdcdly;

/****************stylus down************************/

/*检测子中断源,判断是否是INT_TC中断,且触摸笔按下*/

if(rSUBSRCPND & (BIT_SUB_TC))

{undefined

if( !(rADCDAT0&0x8000))

Uart_Printf("nStylus downn");

else

Uart_Printf("nStylus upn");

}

/*pull-up disable,自动连续X,Y坐标转换*/

rADCTSC = (1<<3)|(1<<2);

saveAdcdly=rADCDLY;

rADCDLY=40000; //Normal conversion mode delay about (1/50M)*40000=0.8ms

/*开始AD转换*/

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 & 0x80000000)); //check if ADC is finished with interrupt bit

/*获取X,Y坐标*/

xdata=(rADCDAT0&0x3ff);

ydata=(rADCDAT1&0x3ff);

ClearSubPending(BIT_SUB_TC);

//ClearPending(BIT_ADC);

rSRCPND = 0x80000000;

rINTPND = 0x80000000;

EnableSubIrq(BIT_SUB_TC);

//EnableIrq(BIT_ADC);

rINTMSK = 0x7fffffff;

/****************stylus down************************/

/****************stylus up**************************/

/*设置触摸屏为等待中断模式,等待触摸笔抬起*/

rADCTSC =0xd3; //Waiting for interrupt

rADCTSC=rADCTSC|(1<<8); // Detect stylus up interrupt signal.

while(1) //to check Pen-up state

{undefined

if(rSUBSRCPND & (BIT_SUB_TC)) //check if ADC is finished with interrupt bit

{undefined

Uart_Printf("Stylus Up Interrupt~!n");

break; //if Stylus is up(1) state

}

}

/****************stylus up**************************/

Uart_Printf("count=%03d XP=%04d, YP=%04dn", count++, xdata, ydata);

rADCDLY=saveAdcdly;

/*设置触摸屏为等待中断模式,等待下次触摸笔按下*/

rADCTSC =0xd3; //Waiting for interrupt

ClearSubPending(BIT_SUB_TC);

//ClearPending(BIT_ADC);

rSRCPND = 0x80000000;

rINTPND = 0x80000000;

EnableSubIrq(BIT_SUB_TC);

//EnableIrq(BIT_ADC);

rINTMSK = 0x7fffffff;

}


百检网秉承“客户至上,服务为先,精诚合作,以人为本”的经营理念,始终站在用户的角度解决问题,为客户提供“一站购物式”的新奇检测体验,打开网站,像挑选商品一样简单,方便。打破行业信息壁垒,建构消费和检测机构之间高效的沟通平台